Class: SchemaTest::Definition
- Inherits:
-
Property::Object
- Object
- Property
- Property::Object
- SchemaTest::Definition
- Defined in:
- lib/schema_test/definition.rb
Constant Summary
Constants inherited from Property::Object
Property::Object::SHORTHAND_ATTRIBUTES, Property::Object::TYPES
Constants inherited from Property
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Attributes inherited from Property::Object
#excluded_property_names, #version
Attributes inherited from Property
Class Method Summary collapse
- .all ⇒ Object
- .find(name, version) ⇒ Object
- .find!(name, version) ⇒ Object
- .register(definition) ⇒ Object
- .reset! ⇒ Object
Instance Method Summary collapse
- #as_json_schema(domain: SchemaTest.configuration.domain) ⇒ Object
-
#initialize(name, location: nil, **attributes) ⇒ Definition
constructor
A new instance of Definition.
Methods inherited from Property::Object
#==, #array, #base_json_schema_type, #based_on, #object, #properties, #resolve
Methods inherited from Property
#==, #base_json_schema_type, #json_schema_format, #json_schema_type, #lookup_object, #nullable, #nullable!, #nullable?, #optional, #optional!, #optional?, #type
Constructor Details
#initialize(name, location: nil, **attributes) ⇒ Definition
Returns a new instance of Definition.
31 32 33 34 35 |
# File 'lib/schema_test/definition.rb', line 31 def initialize(name, location: nil, **attributes) super(name, **attributes) self.class.register(self) @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
29 30 31 |
# File 'lib/schema_test/definition.rb', line 29 def location @location end |
Class Method Details
.all ⇒ Object
19 20 21 |
# File 'lib/schema_test/definition.rb', line 19 def self.all (@definitions || {}).values.flat_map(&:values) end |
.find(name, version) ⇒ Object
15 16 17 |
# File 'lib/schema_test/definition.rb', line 15 def self.find(name, version) (@definitions || {}).dig(name, version) end |
.find!(name, version) ⇒ Object
23 24 25 26 27 |
# File 'lib/schema_test/definition.rb', line 23 def self.find!(name, version) found = find(name, version) raise SchemaTest::Error, "Could not find schema for #{name.inspect} (version: #{version.inspect})" unless found found end |
.register(definition) ⇒ Object
9 10 11 12 13 |
# File 'lib/schema_test/definition.rb', line 9 def self.register(definition) @definitions ||= {} @definitions[definition.name] ||= {} @definitions[definition.name][definition.version] = definition end |
.reset! ⇒ Object
5 6 7 |
# File 'lib/schema_test/definition.rb', line 5 def self.reset! @definitions = nil end |
Instance Method Details
#as_json_schema(domain: SchemaTest.configuration.domain) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/schema_test/definition.rb', line 37 def as_json_schema(domain: SchemaTest.configuration.domain) id_part = version ? "v#{version}/#{name}" : name { '$schema' => SchemaTest::SCHEMA_VERSION, '$id' => "http://#{domain}/#{id_part}.json", 'title' => name.to_s }.merge(super(false)) end |