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

Refactor ref schema URI construction. #177

Merged

Conversation

gabrielg
Copy link
Contributor

@gabrielg gabrielg commented Nov 6, 2014

I'm fairly certain I've found a bug in handling of the id property, but in the process of tracking it down I found some opportunities for refactoring while trying to reason about how schema URIs were constructed. Rather than lump a bug fix and a refactor into the one PR, I'm starting with this PR that just includes the refactoring. Ran all tests and they are passing locally.

This refactors JSON::Validator#load_ref_schema to not implement a lot of logic that Pathname and URI are already capable of, and splits some of it into a separate method for clarity. Some JSON::Validator class methods are also added to hide away the specific implementation of how already loaded schemas are kept around.

  • Refactor JSON::Validator#load_schema_ref to move absolute URI construction to its own method, and to bail ASAP if the schema is already loaded.
  • Add JSON::Validator#absolutize_ref_uri to handle logic around constructing an absolute URI to a schema based on the ref URI and its parent schema URI.
  • Add JSON::Validator.schema_for_uri to fetch an already loaded schema for a given URI.
  • Add JSON::Validator.schema_loaded? predicate method for testing whether a schema is already loaded.
  • Move some existing code to use the new class methods.

This refactors JSON::Validator#load_ref_schema to not implement a lot
of logic that Pathname and URI are already capable of, and splits some
of it into a separate method for clarity. Some JSON::Validator class
methods are also added to hide away the specific implementation of
how already loaded schemas are kept around.

* Refactor JSON::Validator#load_schema_ref to move absolute URI
  construction to its own method, and to bail ASAP if the schema is
  already loaded.
* Add JSON::Validator#absolutize_ref_uri to handle logic around
  constructing an absolute URI to a schema based on the ref URI and
  its parent schema URI.
* Add JSON::Validator.schema_for_uri to fetch an already loaded schema
  for a given URI.
* Add JSON::Validator.schema_loaded? predicate method for testing
  whether a schema is already loaded.
* Move some existing code to use the new class methods.
@pd
Copy link
Contributor

pd commented Nov 7, 2014

LGTM, 👍

I haven't really thought through how this and #178 will interact with @RST-J's #174, tho.

@RST-J
Copy link
Contributor

RST-J commented Nov 7, 2014

Well, it'll probably conflict. But I think we should merge this because it breaks up loading a schema into single blocks of dedicated logic. So 👍
I'll rebase/restart with addressable from here.

RST-J added a commit that referenced this pull request Nov 7, 2014
…ction

Refactor ref schema URI construction.
@RST-J RST-J merged commit 9abc3a3 into voxpupuli:master Nov 7, 2014
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