Class: YamlBSides::Associations::BelongsTo
- Inherits:
-
Base
- Object
- Base
- YamlBSides::Associations::BelongsTo
show all
- Defined in:
- lib/yaml_b_sides/associations/belongs_to.rb
Instance Attribute Summary
Attributes inherited from Base
#name, #opts
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#action ⇒ Object
4
5
6
|
# File 'lib/yaml_b_sides/associations/belongs_to.rb', line 4
def action
:find
end
|
#key ⇒ Object
8
9
10
|
# File 'lib/yaml_b_sides/associations/belongs_to.rb', line 8
def key
"#{name}_id"
end
|
#klass(instance) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/yaml_b_sides/associations/belongs_to.rb', line 16
def klass( instance )
if polymorphic?
class_name = instance.send "#{name}_class"
class_name.constantize
else
super
end
end
|
#query(instance) ⇒ Object
12
13
14
|
# File 'lib/yaml_b_sides/associations/belongs_to.rb', line 12
def query( instance )
instance.send key
end
|