Class: AmsLazyRelationships::Core::LazyRelationshipMeta

Inherits:
Object
  • Object
show all
Defined in:
lib/ams_lazy_relationships/core/lazy_relationship_meta.rb

Overview

Internal helper class for keeping relationship details

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, loader:, reflection:, load_for: nil) ⇒ LazyRelationshipMeta

Returns a new instance of LazyRelationshipMeta.

Parameters:

  • name (String/Symbol)

    lazy relationship name. Can be different than the relationship name

  • loader (Object)

    lazy loader for the relationship. Has to respond to ‘load(record, &block)`.

  • reflection (Object)

    AMS relationship meta. Keeps data like the serializer for the relationship. This data structure differs for various AMS versions.

  • load_for (Symbol) (defaults to: nil)

    Optionally you can delegate the loading to a method defined by ‘load_for` symbol. It is useful e.g. when the loaded object is a decorated object and the real AR model is accessible by calling the decorator’s method.



14
15
16
17
18
19
# File 'lib/ams_lazy_relationships/core/lazy_relationship_meta.rb', line 14

def initialize(name:, loader:, reflection:, load_for: nil)
  @name = name.to_sym
  @loader = loader
  @reflection = reflection
  @load_for = load_for
end

Instance Attribute Details

#load_forObject (readonly)

Returns the value of attribute load_for.



21
22
23
# File 'lib/ams_lazy_relationships/core/lazy_relationship_meta.rb', line 21

def load_for
  @load_for
end

#loaderObject (readonly)

Returns the value of attribute loader.



21
22
23
# File 'lib/ams_lazy_relationships/core/lazy_relationship_meta.rb', line 21

def loader
  @loader
end

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/ams_lazy_relationships/core/lazy_relationship_meta.rb', line 21

def name
  @name
end

#reflectionObject (readonly)

Returns the value of attribute reflection.



21
22
23
# File 'lib/ams_lazy_relationships/core/lazy_relationship_meta.rb', line 21

def reflection
  @reflection
end