hoxworth/json-schema — pull request #177 by gabrielg (2014-11-06 00:43:53+00:00)
Title: Refactor ref schema URI construction.

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.