Class: Friendly::Associations::Association
- Inherits:
-
Object
- Object
- Friendly::Associations::Association
- Defined in:
- lib/friendly/associations/association.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#owner_klass ⇒ Object
readonly
Returns the value of attribute owner_klass.
Instance Method Summary collapse
- #class_name ⇒ Object
- #foreign_key ⇒ Object
-
#initialize(owner_klass, name, options = {}) ⇒ Association
constructor
A new instance of Association.
- #klass ⇒ Object
- #owner_klass_name ⇒ Object
- #scope(document) ⇒ Object
Constructor Details
#initialize(owner_klass, name, options = {}) ⇒ Association
Returns a new instance of Association.
6 7 8 9 10 11 |
# File 'lib/friendly/associations/association.rb', line 6 def initialize(owner_klass, name, = {}) @owner_klass = owner_klass @name = name @class_name = [:class_name] @foreign_key = [:foreign_key] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/friendly/associations/association.rb', line 4 def name @name end |
#owner_klass ⇒ Object (readonly)
Returns the value of attribute owner_klass.
4 5 6 |
# File 'lib/friendly/associations/association.rb', line 4 def owner_klass @owner_klass end |
Instance Method Details
#class_name ⇒ Object
21 22 23 |
# File 'lib/friendly/associations/association.rb', line 21 def class_name @class_name ||= name.to_s.classify end |
#foreign_key ⇒ Object
17 18 19 |
# File 'lib/friendly/associations/association.rb', line 17 def foreign_key @foreign_key ||= [owner_klass_name, :id].join("_").to_sym end |
#klass ⇒ Object
13 14 15 |
# File 'lib/friendly/associations/association.rb', line 13 def klass @klass ||= class_name.constantize end |
#owner_klass_name ⇒ Object
25 26 27 |
# File 'lib/friendly/associations/association.rb', line 25 def owner_klass_name owner_klass.name.to_s.underscore.singularize end |
#scope(document) ⇒ Object
29 30 31 |
# File 'lib/friendly/associations/association.rb', line 29 def scope(document) klass.scope(foreign_key => document.id) end |