Class: JSON::Schema::Reader
- Inherits:
-
Object
- Object
- JSON::Schema::Reader
- Defined in:
- lib/json-schema/schema/reader.rb
Overview
Instance Method Summary collapse
- #accept_file?(pathname) ⇒ Boolean
- #accept_uri?(uri) ⇒ Boolean
-
#initialize(options = {}) ⇒ Reader
constructor
The behavior of the schema reader can be controlled by providing callbacks to determine whether to permit reading referenced schemas.
- #read(location) ⇒ JSON::Schema
Constructor Details
#initialize(options = {}) ⇒ Reader
The behavior of the schema reader can be controlled by providing callbacks to determine whether to permit reading referenced schemas. The options accept_uri
and accept_file
should be procs which accept a URI
or Pathname
object, and return a boolean value indicating whether to read the referenced schema.
URIs using the file
scheme will be normalized into Pathname
objects and passed to the accept_file
callback.
75 76 77 78 |
# File 'lib/json-schema/schema/reader.rb', line 75 def initialize( = {}) @accept_uri = .fetch(:accept_uri, true) @accept_file = .fetch(:accept_file, true) end |
Instance Method Details
#accept_file?(pathname) ⇒ Boolean
111 112 113 114 115 116 117 |
# File 'lib/json-schema/schema/reader.rb', line 111 def accept_file?(pathname) if @accept_file.respond_to?(:call) @accept_file.call(pathname) else @accept_file end end |
#accept_uri?(uri) ⇒ Boolean
101 102 103 104 105 106 107 |
# File 'lib/json-schema/schema/reader.rb', line 101 def accept_uri?(uri) if @accept_uri.respond_to?(:call) @accept_uri.call(uri) else @accept_uri end end |
#read(location) ⇒ JSON::Schema
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/json-schema/schema/reader.rb', line 87 def read(location) uri = JSON::Util::URI.parse(location.to_s) body = if uri.scheme.nil? || uri.scheme == 'file' uri = JSON::Util::URI.file_uri(uri) read_file(Pathname.new(uri.path).) else read_uri(uri) end JSON::Schema.new(JSON::Validator.parse(body), uri) end |