Class: MongoModel::Associations::Base::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mongomodel/concerns/associations/base/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(association) ⇒ Proxy



12
13
14
# File 'lib/mongomodel/concerns/associations/base/proxy.rb', line 12

def initialize(association)
  @association = association
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object (private)



45
46
47
# File 'lib/mongomodel/concerns/associations/base/proxy.rb', line 45

def method_missing(*args, &block)
  target.send(*args, &block)
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association



10
11
12
# File 'lib/mongomodel/concerns/associations/base/proxy.rb', line 10

def association
  @association
end

Instance Method Details

#loaded!Object



31
32
33
# File 'lib/mongomodel/concerns/associations/base/proxy.rb', line 31

def loaded!
  @loaded = true
end

#loaded?Boolean



27
28
29
# File 'lib/mongomodel/concerns/associations/base/proxy.rb', line 27

def loaded?
  @loaded
end

#proxy_respond_to?Object



5
# File 'lib/mongomodel/concerns/associations/base/proxy.rb', line 5

alias_method :proxy_respond_to?, :respond_to?

#resetObject



35
36
37
38
# File 'lib/mongomodel/concerns/associations/base/proxy.rb', line 35

def reset
  @loaded = false
  @target = nil
end

#respond_to?(*args) ⇒ Boolean



40
41
42
# File 'lib/mongomodel/concerns/associations/base/proxy.rb', line 40

def respond_to?(*args)
  proxy_respond_to?(*args) || target.respond_to?(*args)
end

#targetObject



22
23
24
25
# File 'lib/mongomodel/concerns/associations/base/proxy.rb', line 22

def target
  load_target
  @target
end

#target=(new_target) ⇒ Object



16
17
18
19
20
# File 'lib/mongomodel/concerns/associations/base/proxy.rb', line 16

def target=(new_target)
  @target = new_target
  loaded!
  @target
end