class SchemaTest::Definition
Public Class Methods
find(name, version)
click to toggle source
# File lib/schema_test/definition.rb, line 15 def self.find(name, version) (@definitions || {}).dig(name, version) end
find!(name, version)
click to toggle source
# File lib/schema_test/definition.rb, line 19 def self.find!(name, version) found = find(name, version) raise "Could not find schema for #{name.inspect} (version: #{version.inspect})" unless found found end
new(*args)
click to toggle source
Calls superclass method
# File lib/schema_test/definition.rb, line 25 def initialize(*args) super self.class.register(self) end
register(definition)
click to toggle source
# File lib/schema_test/definition.rb, line 9 def self.register(definition) @definitions ||= {} @definitions[definition.name] ||= {} @definitions[definition.name][definition.version] = definition end
reset!()
click to toggle source
# File lib/schema_test/definition.rb, line 5 def self.reset! @definitions = nil end
Public Instance Methods
as_json_schema(domain: SchemaTest.configuration.domain)
click to toggle source
Calls superclass method
# File lib/schema_test/definition.rb, line 43 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
as_structure(_=nil)
click to toggle source
# File lib/schema_test/definition.rb, line 38 def as_structure(_=nil) hashes, others = @properties.values.map(&:as_structure).partition { |x| x.is_a?(Hash) } others + [hashes.inject(&:merge)].compact end
based_on(name, version: self.version)
click to toggle source
# File lib/schema_test/definition.rb, line 52 def based_on(name, version: self.version) other_version = self.class.find(name, version) other_version.properties.values.each do |property| define_property(property.dup) end end
optional(object)
click to toggle source
# File lib/schema_test/definition.rb, line 34 def optional(object) object.optional! end
type(name, version=nil)
click to toggle source
# File lib/schema_test/definition.rb, line 30 def type(name, version=nil) lookup_object(name, version || @version) end