Class: Chassis::Repo::LazyAssociation
- Defined in:
- lib/chassis/repo/lazy_association.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #__getobj__ ⇒ Object
- #class ⇒ Object
- #eql?(other) ⇒ Boolean
- #id ⇒ Object
-
#initialize(repo, id) ⇒ LazyAssociation
constructor
A new instance of LazyAssociation.
- #inspect ⇒ Object
- #instance_of?(klass) ⇒ Boolean
- #is_a?(klass) ⇒ Boolean
- #kind_of?(klass) ⇒ Boolean
- #materialize ⇒ Object
- #repo ⇒ Object
Constructor Details
#initialize(repo, id) ⇒ LazyAssociation
Returns a new instance of LazyAssociation.
4 5 6 |
# File 'lib/chassis/repo/lazy_association.rb', line 4 def initialize(repo, id) @repo, @id = repo, id end |
Instance Method Details
#==(other) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/chassis/repo/lazy_association.rb', line 32 def ==(other) if other.instance_of? self.class other.id == id else other.repo == repo && other.id == id end end |
#__getobj__ ⇒ Object
48 49 50 |
# File 'lib/chassis/repo/lazy_association.rb', line 48 def __getobj__ materialize end |
#class ⇒ Object
12 13 14 |
# File 'lib/chassis/repo/lazy_association.rb', line 12 def class @repo.object_class end |
#eql?(other) ⇒ Boolean
40 41 42 |
# File 'lib/chassis/repo/lazy_association.rb', line 40 def eql?(other) self == other end |
#id ⇒ Object
8 9 10 |
# File 'lib/chassis/repo/lazy_association.rb', line 8 def id @id end |
#inspect ⇒ Object
52 53 54 |
# File 'lib/chassis/repo/lazy_association.rb', line 52 def inspect "#<LazyAssociation:#{object_id} @repo=#{repo} @id=#{id}>" end |
#instance_of?(klass) ⇒ Boolean
20 21 22 |
# File 'lib/chassis/repo/lazy_association.rb', line 20 def instance_of?(klass) self.class == klass end |
#is_a?(klass) ⇒ Boolean
24 25 26 |
# File 'lib/chassis/repo/lazy_association.rb', line 24 def is_a?(klass) instance_of?(klass) || self.class > klass end |
#kind_of?(klass) ⇒ Boolean
28 29 30 |
# File 'lib/chassis/repo/lazy_association.rb', line 28 def kind_of?(klass) is_a? klass end |
#materialize ⇒ Object
44 45 46 |
# File 'lib/chassis/repo/lazy_association.rb', line 44 def materialize @object ||= repo.find id end |
#repo ⇒ Object
16 17 18 |
# File 'lib/chassis/repo/lazy_association.rb', line 16 def repo @repo end |