Class: Isomorphic::Lens::AbstractLens Abstract
- Inherits:
-
Object
- Object
- Isomorphic::Lens::AbstractLens
- Defined in:
- lib/isomorphic/lens.rb
Overview
This class is abstract.
Subclass and override #_get and #set to implement a custom class.
Generic base class for Isomorphic lenses.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#factory ⇒ Isomorphic::Factory::AbstractFactory
readonly
The Isomorphic factory.
-
#inflector ⇒ Object
readonly
Returns the value of attribute inflector.
Instance Method Summary collapse
-
#get(record_or_hash) ⇒ Object
Getter.
-
#initialize(factory, inflector) ⇒ AbstractLens
constructor
Default constructor.
-
#set(record, isomorphism_instance, xmlattr_acc = ::ActiveSupport::HashWithIndifferentAccess.new) ⇒ Object
Setter.
Constructor Details
#initialize(factory, inflector) ⇒ AbstractLens
Default constructor.
81 82 83 84 85 |
# File 'lib/isomorphic/lens.rb', line 81 def initialize(factory, inflector) super() @factory, @inflector = factory, inflector end |
Instance Attribute Details
#factory ⇒ Isomorphic::Factory::AbstractFactory (readonly)
Returns the Isomorphic factory.
75 76 77 |
# File 'lib/isomorphic/lens.rb', line 75 def factory @factory end |
#inflector ⇒ Object (readonly)
Returns the value of attribute inflector.
75 |
# File 'lib/isomorphic/lens.rb', line 75 attr_reader :factory, :inflector |
Instance Method Details
#get(record_or_hash) ⇒ Object
Getter.
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/isomorphic/lens.rb', line 92 def get(record_or_hash) if record_or_hash.is_a?(::Hash) record_or_hash.each_pair.inject({}) { |acc, pair| association_record, record = *pair acc[association_record] = _get(record) acc } else _get(record_or_hash) end end |
#set(record, isomorphism_instance, xmlattr_acc = ::ActiveSupport::HashWithIndifferentAccess.new) ⇒ Object
Setter.
112 113 114 |
# File 'lib/isomorphic/lens.rb', line 112 def set(record, isomorphism_instance, xmlattr_acc = ::ActiveSupport::HashWithIndifferentAccess.new) raise ::NotImplementedError end |