Class: ChainOptions::Util::ContextBoundDelegate
- Inherits:
-
Object
- Object
- ChainOptions::Util::ContextBoundDelegate
show all
- Defined in:
- lib/chain_options/util.rb
Overview
Shamelessly copied from sunspot/sunspot with some alterations
Constant Summary
collapse
- BASIC_METHODS =
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(receiver, calling_context) ⇒ ContextBoundDelegate
Returns a new instance of ContextBoundDelegate.
61
62
63
|
# File 'lib/chain_options/util.rb', line 61
def initialize(receiver, calling_context)
@__receiver__, @__calling_context__ = receiver, calling_context
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
80
81
82
|
# File 'lib/chain_options/util.rb', line 80
def method_missing(method, *args, &block)
__proxy_method__(method, *args, &block)
end
|
Class Method Details
.instance_eval_with_context(receiver, &block) ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/chain_options/util.rb', line 38
def instance_eval_with_context(receiver, &block)
calling_context = eval('self', block.binding, __FILE__, __LINE__)
parent_calling_context = calling_context.instance_eval do
@__calling_context__ if defined?(@__calling_context__)
end
calling_context = parent_calling_context if parent_calling_context
new(receiver, calling_context).instance_eval(&block)
end
|
Instance Method Details
#__proxy_method__(method, *args, &block) ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/chain_options/util.rb', line 88
def __proxy_method__(method, *args, &block)
@__receiver__.__send__(method.to_sym, *args, &block)
rescue ::NoMethodError => e
begin
@__calling_context__.__send__(method.to_sym, *args, &block)
rescue ::NoMethodError
raise(e)
end
end
|
#id ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/chain_options/util.rb', line 65
def id
@__calling_context__.__send__(:id)
rescue ::NoMethodError => e
begin
@__receiver__.__send__(:id)
rescue ::NoMethodError
raise(e)
end
end
|
#respond_to_missing?(meth) ⇒ Boolean
84
85
86
|
# File 'lib/chain_options/util.rb', line 84
def respond_to_missing?(meth)
@__receiver__.respond_to?(meth) || @__calling_context__.respond_to?(meth)
end
|
#sub(*args, &block) ⇒ Object
Special case due to ‘Kernel#sub`’s existence
76
77
78
|
# File 'lib/chain_options/util.rb', line 76
def sub(*args, &block)
__proxy_method__(:sub, *args, &block)
end
|