Module: Traits::Association::Through

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

Instance Method Summary collapse

Instance Method Details

#source_associationObject



26
27
28
29
30
# File 'lib/traits/concerns/association/through.rb', line 26

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

#source_association_nameObject



32
33
34
# File 'lib/traits/concerns/association/through.rb', line 32

def source_association_name
  source_association.try(:name)
end

#throughObject



8
9
10
11
12
# File 'lib/traits/concerns/association/through.rb', line 8

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

#through?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/traits/concerns/association/through.rb', line 4

def through?
  reflection.through_reflection.present?
end

#through_associationObject



20
21
22
23
24
# File 'lib/traits/concerns/association/through.rb', line 20

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

#through_association_nameObject



36
37
38
39
40
# File 'lib/traits/concerns/association/through.rb', line 36

def through_association_name
  if through?
    through_association.name
  end
end

#through_classObject



14
15
16
17
18
# File 'lib/traits/concerns/association/through.rb', line 14

def through_class
  if through?
    through.active_record
  end
end

#through_from_key_nameObject



54
55
56
57
58
# File 'lib/traits/concerns/association/through.rb', line 54

def through_from_key_name
  if through?
    source_association.from_key_name
  end
end

#through_table_nameObject



42
43
44
45
46
# File 'lib/traits/concerns/association/through.rb', line 42

def through_table_name
  if through?
    through_association.to_table_name
  end
end

#through_to_key_nameObject



48
49
50
51
52
# File 'lib/traits/concerns/association/through.rb', line 48

def through_to_key_name
  if through?
    through_association.to_key_name
  end
end

#to_hashObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/traits/concerns/association/through.rb', line 60

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