Class: StructuredStore::RefResolvers::BlankRefResolver
- Defined in:
- lib/structured_store/ref_resolvers/blank_ref_resolver.rb
Overview
This class resolves properties where no $ref is defined.
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’ property 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
10 11 12 |
# File 'lib/structured_store/ref_resolvers/blank_ref_resolver.rb', line 10 def self.matching_ref_pattern /\A\z/ end |
Instance Method Details
#define_attribute ⇒ Proc
Defines the rails attribute(s) on the given singleton class
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/structured_store/ref_resolvers/blank_ref_resolver.rb', line 18 def define_attribute type = property_schema['type'] # Handle arrays return define_array_attribute if type == 'array' 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’ property definition Each element contains a duplicate of the enum option for both the label and value
For arrays, delegates to a resolver for the items to get options recursively
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/structured_store/ref_resolvers/blank_ref_resolver.rb', line 40 def # For arrays, delegate to the items resolver if property_schema['type'] == 'array' items_resolver = create_items_resolver return items_resolver. end # For non-arrays, get enum directly enum = property_schema['enum'] enum&.map { |option| [option, option] } || [] end |