Module: Isomorphic::Memoization

Extended by:
ActiveSupport::Concern
Defined in:
lib/isomorphic/memoization.rb

Overview

Included when the base class can memo-cache the results of getters and setters of Isomorphic lenses.

Instance Method Summary collapse

Instance Method Details

#find_all_with_memo_isomorphism_for(inflector, record, **options) ⇒ ActiveSupport::HashWithIndifferentAccess

Find all memoized instances for the given Active Record record by XML attribute name.

Parameters:

Options Hash (**options):

  • :xmlattrs (Array<#to_s>) — default: []

    the XML attribute names

Returns:

  • (ActiveSupport::HashWithIndifferentAccess)

    the memoized instances by XML attribute name

Raises:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/isomorphic/memoization.rb', line 111

def find_all_with_memo_isomorphism_for(inflector, record, **options)
  association_name = record.class.name.underscore.gsub("/", "_").to_sym

  options[:xmlattrs].try(:inject, ::ActiveSupport::HashWithIndifferentAccess.new) { |xmlattr_acc, xmlattr_name|
    xmlattr_acc[xmlattr_name] = self.class.memo_isomorphism_method_names_by_association_name_for(inflector.base)[association_name].try(:inject, inflector.convert_hash({})) { |acc, method_name|
      attribute_name = :"@xmlattr_#{xmlattr_name}_for_#{method_name}_by_#{association_name}"

      isomorphism_attribute_name = :"@#{method_name}_by_xmlattr_#{xmlattr_name}"

      acc[method_name] ||= instance_variable_get(attribute_name).try { |xmlattr_for_method_name_by_association_name|
        xmlattr_for_method_name_by_association_name[record].try { |xmlattr_for_method_name|
          instance_variable_get(isomorphism_attribute_name).try { |method_name_by_xmlattr|
            method_name_by_xmlattr[xmlattr_for_method_name]
          }
        }
      }

      acc
    }

    xmlattr_acc
  }
end