Class: StructuredStore::RefResolvers::DefinitionsResolver
- Defined in:
- lib/structured_store/ref_resolvers/definitions_resolver.rb
Overview
This class resolves $ref strings that point to definitions within the schema.
Instance Attribute Summary
Attributes inherited from Base
#context, #parent_schema, #property_name, #property_schema, #ref_string
Class Method Summary collapse
Instance Method Summary collapse
-
#define_attribute ⇒ Proc
Defines the rails attribute(s) on the given singleton class.
-
#options_array ⇒ Array<Array>
Returns a two dimensional array of options from the ‘enum’ definition Each element contains a duplicate of the enum option for both the label and value.
Methods inherited from Base
#initialize, register, unregister
Constructor Details
This class inherits a constructor from StructuredStore::RefResolvers::Base
Class Method Details
.matching_ref_pattern ⇒ Object
11 12 13 |
# File 'lib/structured_store/ref_resolvers/definitions_resolver.rb', line 11 def self.matching_ref_pattern %r{\A#/definitions/} end |
Instance Method Details
#define_attribute ⇒ Proc
Defines the rails attribute(s) on the given singleton class
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/structured_store/ref_resolvers/definitions_resolver.rb', line 19 def define_attribute type = local_definition['type'] unless %w[boolean integer string].include?(type) raise "Unsupported attribute type: #{type.inspect} for property '#{property_name}'" end # Define the attribute on the singleton class of the object lambda do |object| object.singleton_class.attribute(property_name, type.to_sym) end end |
#options_array ⇒ Array<Array>
Returns a two dimensional array of options from the ‘enum’ definition Each element contains a duplicate of the enum option for both the label and value
36 37 38 39 40 |
# File 'lib/structured_store/ref_resolvers/definitions_resolver.rb', line 36 def enum = local_definition['enum'] enum.map { |option| [option, option] } end |