Class: Shamu::Services::LazyAssociation
- Inherits:
-
Delegator
- Object
- Delegator
- Shamu::Services::LazyAssociation
- Defined in:
- lib/shamu/services/lazy_association.rb
Overview
Lazily look up an associated resource
Attributes collapse
-
#id ⇒ Object
The primary key id of the association.
Instance Method Summary collapse
- #__getobj__ ⇒ Object
-
#initialize(id, &block) ⇒ LazyAssociation
constructor
A new instance of LazyAssociation.
Constructor Details
#initialize(id, &block) ⇒ LazyAssociation
Returns a new instance of LazyAssociation.
19 20 21 22 |
# File 'lib/shamu/services/lazy_association.rb', line 19 def initialize( id, &block ) @id = id @block = block end |
Instance Attribute Details
#id ⇒ Object
Returns the primary key id of the association. Not delegated so it is safe to use and will not trigger an unnecessary fetch.
14 15 16 |
# File 'lib/shamu/services/lazy_association.rb', line 14 def id @id end |
Instance Method Details
#__getobj__ ⇒ Object
24 25 26 27 28 |
# File 'lib/shamu/services/lazy_association.rb', line 24 def __getobj__ return @association if defined? @association @association = @block.call end |