Module: Isomorphic::Lens::Internal::InstanceMethodsForLens

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

Overview

Included when the base class has a #factory and #inflector, and hence, can build Isomorphic lenses.

Instance Method Summary collapse

Instance Method Details

#reflect_on_association(association) ⇒ Isomorphic::Lens::Association

Build a lens for the Active Record association with the given name.

Parameters:

  • association (#to_s)

    the association name

Returns:



41
42
43
# File 'lib/isomorphic/lens.rb', line 41

def reflect_on_association(association)
  Isomorphic::Lens::Association.new(factory, inflector, association, nil)
end

#reflect_on_attribute(attribute_name, to = nil, from = nil) ⇒ Isomorphic::Lens::Attribute

Build a lens for the attribute with the given name.

Parameters:

  • attribute_name (#to_s)

    the attribute name

  • to (Proc) (defaults to: nil)

    the optional modifier for after the getter

  • from (Proc) (defaults to: nil)

    the optional modifier for before the setter

Returns:



51
52
53
# File 'lib/isomorphic/lens.rb', line 51

def reflect_on_attribute(attribute_name, to = nil, from = nil)
  Isomorphic::Lens::Attribute.new(factory, inflector, attribute_name, to, from)
end

#reflect_on_isomorphism(terms, *args) ⇒ Isomorphic::Lens::Isomorphism

Build a lens for the given inflectable terms and optional arguments.

Parameters:

  • terms (Array<Object>)

    the inflectable terms

  • args (Array<Object>)

    the arguments for the isomorphism

Returns:

Raises:



61
62
63
# File 'lib/isomorphic/lens.rb', line 61

def reflect_on_isomorphism(terms, *args)
  Isomorphic::Lens::Isomorphism.new(factory, inflector, terms, *args)
end