Class: Isomorphic::Lens::Isomorphism

Inherits:
AbstractLens show all
Defined in:
lib/isomorphic/lens.rb

Overview

An Isomorphic lens for inflectable terms.

Direct Known Subclasses

IsomorphismAssociation

Instance Attribute Summary collapse

Attributes inherited from AbstractLens

#factory, #inflector

Instance Method Summary collapse

Methods inherited from AbstractLens

#get

Constructor Details

#initialize(factory, inflector, terms, *args) ⇒ Isomorphism

Default constructor.

Parameters:

Raises:



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

#argsObject (readonly)

Returns the value of attribute args.



311
# File 'lib/isomorphic/lens.rb', line 311

attr_reader :terms, :args

#method_nameObject (readonly)

Returns the value of attribute method_name.



315
316
317
# File 'lib/isomorphic/lens.rb', line 315

def method_name
  @method_name
end

#termsArray<Object> (readonly)

Returns the inflectable terms.

Returns:

  • (Array<Object>)

    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