Class: StructuredStore::RefResolvers::JsonDateRangeResolver
- Defined in:
- lib/structured_store/ref_resolvers/json_date_range_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 an empty array of options for date ranges.
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/json_date_range_resolver.rb', line 10 def self.matching_ref_pattern %r{\Aexternal://structured_store/json_date_range/} 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 33 34 35 36 37 38 39 |
# File 'lib/structured_store/ref_resolvers/json_date_range_resolver.rb', line 18 def define_attribute # Capture the property name and store column name in local variables for closure. # context[:column_name] is set by Storable#property_resolvers; fall back to 'store' # for any resolver instantiated without that context (e.g. in isolation in tests). prop_name = property_name col_name = (context[:column_name] || 'store').to_s resolver = self # Define the attribute on the singleton class of the object lambda do |object| converter = object.date_range_converter # Define custom getter and setter methods object.singleton_class.define_method(prop_name) do resolver.send(:cast_stored_value, send(col_name), prop_name, converter) end object.singleton_class.define_method("#{prop_name}=") do |value| resolver.send(:serialize_value_to_store, self, col_name, prop_name, value, converter) end end end |
#options_array ⇒ Array<Array>
Returns an empty array of options for date ranges
44 45 46 |
# File 'lib/structured_store/ref_resolvers/json_date_range_resolver.rb', line 44 def [] end |