Class: JsonSchemaRails::SchemaValidator::MetaSchemas
- Inherits:
-
Object
- Object
- JsonSchemaRails::SchemaValidator::MetaSchemas
- Includes:
- Enumerable
- Defined in:
- lib/json_schema_rails/schema_validator.rb
Instance Method Summary collapse
- #<<(schema) ⇒ Object
- #[](schema_uri) ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ MetaSchemas
constructor
A new instance of MetaSchemas.
- #lookup!(schema_uri) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ MetaSchemas
Returns a new instance of MetaSchemas.
47 48 49 50 |
# File 'lib/json_schema_rails/schema_validator.rb', line 47 def initialize @store = JsonSchema::DocumentStore.new @expander = JsonSchema::ReferenceExpander.new end |
Instance Method Details
#<<(schema) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/json_schema_rails/schema_validator.rb', line 52 def <<(schema) Array(schema).each do |file| schema.(store: @store) @store.add_schema(schema) end end |
#[](schema_uri) ⇒ Object
59 60 61 |
# File 'lib/json_schema_rails/schema_validator.rb', line 59 def [](schema_uri) @store.lookup_schema(schema_uri.sub(/#+$/, '')) end |
#each ⇒ Object
68 69 70 |
# File 'lib/json_schema_rails/schema_validator.rb', line 68 def each @store.each { |k, v| yield v } end |
#lookup!(schema_uri) ⇒ Object
63 64 65 66 |
# File 'lib/json_schema_rails/schema_validator.rb', line 63 def lookup!(schema_uri) self[schema_uri] or raise JsonSchemaRails::SchemaNotFound, "Unknown $schema: #{schema_uri}" end |
#size ⇒ Object
72 73 74 |
# File 'lib/json_schema_rails/schema_validator.rb', line 72 def size reduce(0) { |sum, n| sum + 1 } end |