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