Class: StructuredStore::RefResolvers::JsonDateRangeResolver

Inherits:
Base
  • Object
show all
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

Methods inherited from Base

#initialize, register, unregister

Constructor Details

This class inherits a constructor from StructuredStore::RefResolvers::Base

Class Method Details

.matching_ref_patternObject



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_attributeProc

Defines the rails attribute(s) on the given singleton class

Returns:

  • (Proc)

    a lambda that defines the attribute on the singleton class

Raises:

  • (RuntimeError)

    if the property type is unsupported



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/structured_store/ref_resolvers/json_date_range_resolver.rb', line 18

def define_attribute
  # Capture the property name in a local variable for closure
  prop_name = property_name
  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, store, prop_name, converter)
    end

    object.singleton_class.define_method("#{prop_name}=") do |value|
      resolver.send(:serialize_value_to_store, self, prop_name, value, converter)
    end
  end
end

#options_arrayArray<Array>

Returns an empty array of options for date ranges

Returns:

  • (Array<Array>)

    Array of arrays containing id, value option pairs



41
42
43
# File 'lib/structured_store/ref_resolvers/json_date_range_resolver.rb', line 41

def options_array
  []
end