Class: Tenacity::AssociateProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/tenacity/associate_proxy.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(target, association) ⇒ AssociateProxy



6
7
8
9
10
11
# File 'lib/tenacity/associate_proxy.rb', line 6

def initialize(target, association)
  raise "Cannot create a Tenacity::AssociateProxy with a nil target" if target.nil?
  @target = target
  @association = association
  @marked_for_destruction = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



48
49
50
51
52
53
54
# File 'lib/tenacity/associate_proxy.rb', line 48

def method_missing(method, *args)
  if block_given?
    @target.send(method, *args) { |*block_args| yield(*block_args) }
  else
    @target.send(method, *args)
  end
end

Instance Method Details

#===(other) ⇒ Object

Explicitly proxy === because the instance method removal above doesn’t catch it.



18
19
20
# File 'lib/tenacity/associate_proxy.rb', line 18

def ===(other)
  other === @target
end

#association_targetObject



34
35
36
# File 'lib/tenacity/associate_proxy.rb', line 34

def association_target
  @target
end

#inspectObject



22
23
24
# File 'lib/tenacity/associate_proxy.rb', line 22

def inspect
  @target.inspect
end

#mark_for_destructionObject



38
39
40
# File 'lib/tenacity/associate_proxy.rb', line 38

def mark_for_destruction
  @marked_for_destruction = true
end

#marked_for_destruction?Boolean



42
43
44
# File 'lib/tenacity/associate_proxy.rb', line 42

def marked_for_destruction?
  @marked_for_destruction
end

#proxy_respond_to?Object



3
# File 'lib/tenacity/associate_proxy.rb', line 3

alias_method :proxy_respond_to?, :respond_to?

#respond_to?(*args) ⇒ Boolean



13
14
15
# File 'lib/tenacity/associate_proxy.rb', line 13

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

#save(*args) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/tenacity/associate_proxy.rb', line 26

def save(*args)
  if @association.readonly?
    raise ReadOnlyError
  else
    @target._t_save_if_dirty(*args)
  end
end