Class: YamlBSides::Associations::BelongsTo

Inherits:
Base
  • Object
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

Constructor Details

This class inherits a constructor from YamlBSides::Associations::Base

Instance Method Details

#actionObject



4
5
6
# File 'lib/yaml_b_sides/associations/belongs_to.rb', line 4

def action
  :find
end

#keyObject



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