Class: Traits::Association

Inherits:
Base
  • Object
show all
Includes:
EssayShortcuts, Intermediate, Join, Macro, Members, Naming, Polymorphism, ReadOnly, Through
Defined in:
lib/traits/association.rb,
lib/traits/association.rb,
lib/traits/association/join.rb,
lib/traits/association/macro.rb,
lib/traits/association/naming.rb,
lib/traits/association/members.rb,
lib/traits/association/through.rb,
lib/traits/association/read_only.rb,
lib/traits/association/intermediate.rb,
lib/traits/association/polymorphism.rb,
lib/traits/association/essay_shortcuts.rb

Defined Under Namespace

Modules: EssayShortcuts, Intermediate, Join, Macro, Members, Naming, Polymorphism, ReadOnly, Through

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EssayShortcuts

#features

Methods included from Polymorphism

#accepted_classes_through_polymorphism, #attribute_for_polymorphic_type, #attribute_name_for_polymorphic_type, #paired_through_polymorphism?, #polymorphic?, #to_hash

Methods included from ReadOnly

#mutable?, #readonly?, #to_hash

Methods included from Join

#from_key, #from_key_name, #from_table, #from_table_alias, #from_table_name, #to_hash, #to_key, #to_key_name, #to_table, #to_table_alias, #to_table_name

Methods included from Through

#source_association, #source_association_name, #through, #through?, #through_association, #through_association_name, #through_class, #through_from_key_name, #through_table_name, #through_to_key_name, #to_hash

Methods included from Intermediate

#intermediate?, #intermediate_from_key, #intermediate_from_key_name, #intermediate_table, #intermediate_table_name, #intermediate_to_key, #intermediate_to_key_name, #to_hash

Methods included from Macro

#belongs_to?, #has_and_belongs_to_many?, #has_many?, #has_one?, #short_macro, #to_hash, #to_many?, #to_one?

Methods included from Naming

#plural_name, #to_hash

Methods included from Members

#from, #from_class, #self_to_self?, #to, #to_class, #to_hash

Methods inherited from Base

#to_hash

Constructor Details

#initialize(model_class, reflection) ⇒ Association

Returns a new instance of Association.



33
34
35
36
# File 'lib/traits/association.rb', line 33

def initialize(model_class, reflection)
  @from_class = model_class
  @reflection = reflection
end

Instance Attribute Details

#reflectionObject (readonly)

Returns the value of attribute reflection.



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

def reflection
  @reflection
end

Instance Method Details

#inspectObject



38
39
40
# File 'lib/traits/association.rb', line 38

def inspect
  "#{from.class_name}##{name}"
end

#to_sObject



42
43
44
# File 'lib/traits/association.rb', line 42

def to_s
  name
end

#validatorsObject



50
51
52
# File 'lib/traits/association.rb', line 50

def validators
  from_class.validators_on(name)
end

#value_from(model) ⇒ Object



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

def value_from(model)
  model.send(name)
end