Class: Reynard::Schema
- Inherits:
-
Object
- Object
- Reynard::Schema
- Defined in:
- lib/reynard/schema.rb,
lib/reynard/schema/model_naming.rb
Overview
Holds a references to a schema definition in the specification.
Defined Under Namespace
Classes: ModelNaming
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
-
#initialize(specification:, node:, namespace: nil) ⇒ Schema
constructor
A new instance of Schema.
-
#item_schema ⇒ Object
Returns the schema for items when the current schema is an array.
- #model_name ⇒ Object
-
#property_schema(name) ⇒ Object
Returns the schema for a propery in the schema.
- #type ⇒ Object
Constructor Details
#initialize(specification:, node:, namespace: nil) ⇒ Schema
Returns a new instance of Schema.
10 11 12 13 14 |
# File 'lib/reynard/schema.rb', line 10 def initialize(specification:, node:, namespace: nil) @specification = specification @node = node @namespace = namespace end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
8 9 10 |
# File 'lib/reynard/schema.rb', line 8 def namespace @namespace end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
8 9 10 |
# File 'lib/reynard/schema.rb', line 8 def node @node end |
Instance Method Details
#item_schema ⇒ Object
Returns the schema for items when the current schema is an array.
27 28 29 30 31 32 33 34 35 |
# File 'lib/reynard/schema.rb', line 27 def item_schema return unless type == 'array' self.class.new( specification: @specification, node: [*node, 'items'], namespace: [*namespace, model_name] ) end |
#model_name ⇒ Object
22 23 24 |
# File 'lib/reynard/schema.rb', line 22 def model_name @model_name || model_naming.model_name end |
#property_schema(name) ⇒ Object
Returns the schema for a propery in the schema.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/reynard/schema.rb', line 38 def property_schema(name) property_node = [*node, 'properties', name.to_s] return unless @specification.dig(*property_node) self.class.new( specification: @specification, node: property_node, namespace: [*namespace, model_name] ) end |
#type ⇒ Object
16 17 18 19 20 |
# File 'lib/reynard/schema.rb', line 16 def type return @type if defined?(@type) @type = @specification.dig(*node, 'type') end |