Module: Traits::Association::Through

Included in:
Traits::Association
Defined in:
lib/traits/association/through.rb

Instance Method Summary collapse

Instance Method Details

#source_associationObject



29
30
31
32
33
# File 'lib/traits/association/through.rb', line 29

def source_association
  if through?
    through.associations[reflection.source_reflection.name]
  end
end

#source_association_nameObject



35
36
37
# File 'lib/traits/association/through.rb', line 35

def source_association_name
  source_association.try(:name)
end

#throughObject



11
12
13
14
15
# File 'lib/traits/association/through.rb', line 11

def through
  if through?
    reflection.through_reflection.klass.traits
  end
end

#through?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/traits/association/through.rb', line 7

def through?
  reflection.through_reflection.present?
end

#through_associationObject



23
24
25
26
27
# File 'lib/traits/association/through.rb', line 23

def through_association
  if through?
    from.associations[reflection.through_reflection.name]
  end
end

#through_association_nameObject



39
40
41
42
43
# File 'lib/traits/association/through.rb', line 39

def through_association_name
  if through?
    through_association.name
  end
end

#through_classObject



17
18
19
20
21
# File 'lib/traits/association/through.rb', line 17

def through_class
  if through?
    through.active_record
  end
end

#through_from_key_nameObject



57
58
59
60
61
# File 'lib/traits/association/through.rb', line 57

def through_from_key_name
  if through?
    source_association.from_key_name
  end
end

#through_table_nameObject



45
46
47
48
49
# File 'lib/traits/association/through.rb', line 45

def through_table_name
  if through?
    through_association.to_table_name
  end
end

#through_to_key_nameObject



51
52
53
54
55
# File 'lib/traits/association/through.rb', line 51

def through_to_key_name
  if through?
    through_association.to_key_name
  end
end

#to_hashObject



63
64
65
66
67
68
69
70
71
72
# File 'lib/traits/association/through.rb', line 63

def to_hash
  super.merge!(
    through:               through.try(:name),
    through_association:   through_association_name,
    source_association:    source_association_name,
    through_table_name:    through_table_name,
    through_to_key_name:   through_to_key_name,
    through_from_key_name: through_from_key_name
  )
end