Class: Superstore::Associations::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/superstore/associations/association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, reflection) ⇒ Association

Returns a new instance of Association.



7
8
9
10
# File 'lib/superstore/associations/association.rb', line 7

def initialize(owner, reflection)
  @owner = owner
  @reflection = reflection
end

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



4
5
6
# File 'lib/superstore/associations/association.rb', line 4

def owner
  @owner
end

#reflectionObject (readonly)

Returns the value of attribute reflection.



4
5
6
# File 'lib/superstore/associations/association.rb', line 4

def reflection
  @reflection
end

Instance Method Details

#association_classObject



12
13
14
# File 'lib/superstore/associations/association.rb', line 12

def association_class
  association_class_name.constantize
end

#association_class_nameObject



16
17
18
# File 'lib/superstore/associations/association.rb', line 16

def association_class_name
  reflection.polymorphic? ? owner.send(reflection.polymorphic_column) : reflection.class_name
end

#loaded!Object



33
34
35
# File 'lib/superstore/associations/association.rb', line 33

def loaded!
  @loaded = true
end

#loaded?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/superstore/associations/association.rb', line 29

def loaded?
  @loaded
end

#targetObject



25
26
27
# File 'lib/superstore/associations/association.rb', line 25

def target
  @target
end

#target=(target) ⇒ Object



20
21
22
23
# File 'lib/superstore/associations/association.rb', line 20

def target=(target)
  @target = target
  loaded!
end