Class: Ripple::Associations::Proxy

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

Direct Known Subclasses

ManyEmbeddedProxy, ManyLinkedProxy, OneEmbeddedProxy, OneLinkedProxy

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Proxy) initialize(owner, reflection)

A new instance of Proxy



35
36
37
38
39
# File 'ripple/lib/ripple/associations/proxy.rb', line 35

def initialize(owner, reflection)
  @owner, @reflection = owner, reflection
  Array(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
  reset
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args, &block) (protected)



103
104
105
106
107
108
109
110
111
# File 'ripple/lib/ripple/associations/proxy.rb', line 103

def method_missing(method, *args, &block)
  load_target

  if block_given?
    target.send(method, *args)  { |*block_args| block.call(*block_args) }
  else
    target.send(method, *args)
  end
end

Instance Attribute Details

- (Object) owner (readonly) Also known as: proxy_owner

Returns the value of attribute owner



25
26
27
# File 'ripple/lib/ripple/associations/proxy.rb', line 25

def owner
  @owner
end

- (Object) reflection (readonly) Also known as: proxy_reflection

Returns the value of attribute reflection



25
26
27
# File 'ripple/lib/ripple/associations/proxy.rb', line 25

def reflection
  @reflection
end

- (Object) target (readonly) Also known as: proxy_target

Returns the value of attribute target



25
26
27
# File 'ripple/lib/ripple/associations/proxy.rb', line 25

def target
  @target
end

Instance Method Details

- (Object) ===(other)



97
98
99
100
# File 'ripple/lib/ripple/associations/proxy.rb', line 97

def ===(other)
  load_target
  other === target
end

- (Boolean) blank?

Returns:



59
60
61
62
# File 'ripple/lib/ripple/associations/proxy.rb', line 59

def blank?
  load_target
  target.blank?
end

- (Object) inspect



41
42
43
44
# File 'ripple/lib/ripple/associations/proxy.rb', line 41

def inspect
  load_target
  target.inspect
end

- (Object) loaded



50
51
52
# File 'ripple/lib/ripple/associations/proxy.rb', line 50

def loaded
  @loaded = true
end

- (Boolean) loaded?

Returns:



46
47
48
# File 'ripple/lib/ripple/associations/proxy.rb', line 46

def loaded?
  @loaded
end

- (Boolean) nil?

Returns:



54
55
56
57
# File 'ripple/lib/ripple/associations/proxy.rb', line 54

def nil?
  load_target
  target.nil?
end

- (Boolean) present?

Returns:



64
65
66
67
# File 'ripple/lib/ripple/associations/proxy.rb', line 64

def present?
  load_target
  target.present?
end

- (Object) proxy_respond_to?



20
# File 'ripple/lib/ripple/associations/proxy.rb', line 20

alias :proxy_respond_to? :respond_to?

- (Object) reload



69
70
71
72
73
# File 'ripple/lib/ripple/associations/proxy.rb', line 69

def reload
  reset
  load_target
  self unless target.nil?
end

- (Object) replace(v)

Raises:

  • (NotImplementedError)


75
76
77
# File 'ripple/lib/ripple/associations/proxy.rb', line 75

def replace(v)
  raise NotImplementedError
end

- (Object) reset



79
80
81
82
# File 'ripple/lib/ripple/associations/proxy.rb', line 79

def reset
  @loaded = false
  @target = nil
end

- (Boolean) respond_to?(*args)

Returns:



84
85
86
# File 'ripple/lib/ripple/associations/proxy.rb', line 84

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

- (Object) send(method, *args, &block)



88
89
90
91
92
93
94
95
# File 'ripple/lib/ripple/associations/proxy.rb', line 88

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