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
11
# File 'lib/superstore/associations/association.rb', line 7

def initialize(owner, reflection)
  @owner = owner
  @reflection = reflection
  reset
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



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

def association_class
  association_class_name.constantize
end

#association_class_nameObject



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

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

#loaded!Object



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

def loaded!
  @loaded = true
end

#loaded?Boolean

Returns:

  • (Boolean)


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

def loaded?
  @loaded
end

#resetObject



38
39
40
41
# File 'lib/superstore/associations/association.rb', line 38

def reset
  @loaded = false
  @target = nil
end

#targetObject



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

def target
  @target
end

#target=(target) ⇒ Object



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

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