Class: LucidWorks::Associations::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/lucid_works/associations/proxy.rb

Overview

This is the root class of our association proxies:

Associations
  Proxy
    HasOne
    HasMany

Direct Known Subclasses

HasMany, HasOne

Instance Method Summary collapse

Constructor Details

#initialize(owner, target_class, options = {}) ⇒ Proxy

Returns a new instance of Proxy.



14
15
16
17
# File 'lib/lucid_works/associations/proxy.rb', line 14

def initialize(owner, target_class, options={})
  @owner, @target_class, @options = owner, target_class, options
  @target = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Forwards any missing method call to the target.



40
41
42
43
44
45
46
47
48
# File 'lib/lucid_works/associations/proxy.rb', line 40

def method_missing(method, *args, &block)
  if load_target
    if @target.respond_to?(method)
      @target.send(method, *args, &block)
    else
      super
    end
  end
end

Instance Method Details

#loaded?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/lucid_works/associations/proxy.rb', line 24

def loaded?
  !!@target
end

#reload!Object



33
34
35
# File 'lib/lucid_works/associations/proxy.rb', line 33

def reload!
  load_target(:force => true)
end

#retrieveable_en_masse?Boolean

Can targets be retrieved for all owners of this type, in one step using owner/all/target

Returns:

  • (Boolean)


29
30
31
# File 'lib/lucid_works/associations/proxy.rb', line 29

def retrieveable_en_masse?
  @options[:retrieveable_en_masse]
end

#target=(target) ⇒ Object

Sets the target of this proxy to \target.



20
21
22
# File 'lib/lucid_works/associations/proxy.rb', line 20

def target=(target)
  @target = target
end