Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General cleanup, mostly focused on attributes/* #172

Merged
merged 12 commits into from
Nov 15, 2014

Conversation

pd
Copy link
Contributor

@pd pd commented Nov 2, 2014

Driven mostly by running flog, flay and reek locally; CodeClimate comparison is available here.

Showing 39 changed files with 528 additions and 605 deletions., but that's largely due to removing a level or two of indents from the FooAttribute classes.

Primary changes:

  1. Almost all FooAttribute classes started with if data.is_a?(Foo); converted these to return unless data.is_a?(Foo). See bc04d2f.
  2. Introduce locals for repeated traversals of objects (eg, current_schema.schema).
  3. minLength, maxItems, maximum, etc etc all derive from a LimitAttribute class, and live in the same file (175e7dc). I don't really like growing the class hierarchy, and LimitAttribute itself is now too abstract for my taste, but each of those classes were previously copypasta with mostly one or two keywords changed.
  4. I can't get 1.8 to run locally (segfaults loading rubygems!), but I think I've fixed the NoMethodError: undefined method 'keys' for [["c", "c"]]:Array error there.

If this is too big/insane to review reasonably, lemme know. I could pull the unnesting commit out of this and do it in a separate PR instead, which might make this more grokkable.

pd added 12 commits November 1, 2014 15:24
Many/most began with a guard against the data type; this just lessens
some of the rightward drift to make them slightly more approachable and
and reduce the CodeClimate complexity score a bit.
Mostly extractions to local variables or minor unnesting.
The code in `limit.rb` is a bit insane and over-abstract now, but I'm
trying to keep the same classes in place for now so that I don't
simultaneously have to rewrite a ton of Schema::Draft1, ::Draft2 etc.
@iainbeeston
Copy link
Contributor

Wow... Great work, it was on my list of things to do something like this (although I was going to limit it to just the properties and properties v4 attribute).

Unfortunately it is a bit hard to code review. I've had a (very) quick read through and I didn't see anything unnerving.

I would be a lot more confident about merging this if I had an idea of what code coverage we have for attributes. Have you tried running simplecov over this branch and checked how well covered the attributes are? (If not I would suggest using it as a guide to add a few more tests in any coverage "black-holes")

This is definitely the right direction to be going in though, IMO

@pd
Copy link
Contributor Author

pd commented Nov 3, 2014

Coverage is pretty decent around attributes. I've pushed two separate branches to my fork for before/after coverage metrics (on the 2.1 run in this case, but it's roughly the same for 1.9, 2.0, jruby, rbx): master-coverage and climate-coverage.

There are uncovered paths, but nothing new that I can identify except some of my raise NotImplementedError method bodies, since those shouldn't ever be hit. Some of the gaps on master are now covered since they've been combined; eg, properties_v4 previously lacked coverage of strict + patternProperties, but it seems v3 did hit that, so v4 gets it for free now.

@pd
Copy link
Contributor Author

pd commented Nov 3, 2014

One unnerving thing, though unrelated to this branch it seems: once we enable simplecov, an IPv4 format test is reliably failing. This issue already exists on master.

Both branches are listed here, and an example of the failure is here.

@iainbeeston
Copy link
Contributor

Well ignoring, that I'd be happy to see this merged, pending more people taking a look=

@RST-J
Copy link
Contributor

RST-J commented Nov 10, 2014

I waded through, except for f23f39b - I simply don't have the mental capability left to finish this thoroughly now ;-).
Really a great improvement, nice work @pd
While reviewing, I mostly compared to what the old code did and what I expected from the context in which the refactoring took place. For the greater changes, I hope we can also rely on the test suite.

@RST-J
Copy link
Contributor

RST-J commented Nov 15, 2014

👍

RST-J added a commit that referenced this pull request Nov 15, 2014
General cleanup, mostly focused on attributes/*
@RST-J RST-J merged commit 4ca80f0 into voxpupuli:master Nov 15, 2014
@pd pd deleted the better-climate branch November 22, 2014 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants