Class: Isomorphic::Lens::Isomorphism
- Inherits:
-
AbstractLens
- Object
- AbstractLens
- Isomorphic::Lens::Isomorphism
- Defined in:
- lib/isomorphic/lens.rb
Overview
An Isomorphic lens for inflectable terms.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#terms ⇒ Array<Object>
readonly
The inflectable terms.
Attributes inherited from AbstractLens
Instance Method Summary collapse
-
#initialize(factory, inflector, terms, *args) ⇒ Isomorphism
constructor
Default constructor.
- #set(record, isomorphism_instance, xmlattr_acc = ::ActiveSupport::HashWithIndifferentAccess.new) ⇒ Object
Methods inherited from AbstractLens
Constructor Details
#initialize(factory, inflector, terms, *args) ⇒ Isomorphism
Default constructor.
324 325 326 327 328 329 330 331 |
# File 'lib/isomorphic/lens.rb', line 324 def initialize(factory, inflector, terms, *args) super(factory, inflector) @terms = terms @args = args @method_name = inflector.isomorphism(terms) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
311 |
# File 'lib/isomorphic/lens.rb', line 311 attr_reader :terms, :args |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
315 316 317 |
# File 'lib/isomorphic/lens.rb', line 315 def method_name @method_name end |
#terms ⇒ Array<Object> (readonly)
Returns the inflectable terms.
311 312 313 |
# File 'lib/isomorphic/lens.rb', line 311 def terms @terms end |
Instance Method Details
#set(record, isomorphism_instance, xmlattr_acc = ::ActiveSupport::HashWithIndifferentAccess.new) ⇒ Object
333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/isomorphic/lens.rb', line 333 def set(record, isomorphism_instance, xmlattr_acc = ::ActiveSupport::HashWithIndifferentAccess.new) (record.class.try(:"has_#{method_name}?") ? record.class.send(:"from_#{method_name}", isomorphism_instance, record, xmlattr_acc, *args) : record.class.send(:"from_#{method_name}", isomorphism_instance, *args)).try { |association_record| factory.xmlattrs.try(:each) do |xmlattr_name| isomorphism_instance.try(:"xmlattr_#{xmlattr_name}").try { |xmlattr_value| xmlattr_acc[xmlattr_name] ||= {} xmlattr_acc[xmlattr_name][xmlattr_value] = association_record } end association_record } end |