Class: Chassis::Repo::LazyAssociation

Inherits:
Proxy
  • Object
show all
Defined in:
lib/chassis/repo/lazy_association.rb

Instance Method Summary collapse

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

#classObject



12
13
14
# File 'lib/chassis/repo/lazy_association.rb', line 12

def class
  @repo.object_class
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/chassis/repo/lazy_association.rb', line 40

def eql?(other)
  self == other
end

#idObject



8
9
10
# File 'lib/chassis/repo/lazy_association.rb', line 8

def id
  @id
end

#inspectObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


28
29
30
# File 'lib/chassis/repo/lazy_association.rb', line 28

def kind_of?(klass)
  is_a? klass
end

#materializeObject



44
45
46
# File 'lib/chassis/repo/lazy_association.rb', line 44

def materialize
  @object ||= repo.find id
end

#repoObject



16
17
18
# File 'lib/chassis/repo/lazy_association.rb', line 16

def repo
  @repo
end