classproxy 0.7.11 → 0.7.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/classproxy/classproxy.rb +34 -34
- data/lib/classproxy/version.rb +1 -1
- metadata +3 -3
@@ -103,7 +103,7 @@ module ClassProxy
|
|
103
103
|
def run_fallback(args, _self=nil)
|
104
104
|
_self ||= self.new
|
105
105
|
|
106
|
-
_self.instance_eval "@
|
106
|
+
_self.instance_eval "@fallbacks_used ||= []"
|
107
107
|
|
108
108
|
fallback_obj = _self.instance_exec args, &@fallback_fetch
|
109
109
|
|
@@ -118,13 +118,13 @@ module ClassProxy
|
|
118
118
|
# check if its set to something else
|
119
119
|
get_method = _self.respond_to?("no_proxy_#{key}") ? "no_proxy_#{key}" : key
|
120
120
|
if _self.respond_to? get_method and _self.send(get_method) == nil
|
121
|
-
|
122
|
-
_self.send("#{key}=", value)
|
123
|
-
_self.instance_eval "@proxied_with_nil << key.to_sym" if value == nil
|
121
|
+
_self.send("#{key}=", fallback_obj.send(key))
|
124
122
|
end
|
125
123
|
end
|
126
124
|
end
|
127
125
|
|
126
|
+
_self.instance_eval '@fallbacks_used << "default"'
|
127
|
+
|
128
128
|
return _self
|
129
129
|
end
|
130
130
|
|
@@ -143,39 +143,39 @@ module ClassProxy
|
|
143
143
|
# here and the setter is being used when appropriate, the @mutex_in_call_for
|
144
144
|
# prevents endless recursion.
|
145
145
|
@mutex_in_call_for ||= []
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
else
|
164
|
-
# This method has no callback, so just run the fallback
|
165
|
-
args_class = ArgsClass.new(self)
|
166
|
-
self.class.send :run_fallback, args_class, self
|
167
|
-
|
168
|
-
# The value might have changed, so check here
|
169
|
-
v = self.send("no_proxy_#{method_name}".to_sym)
|
170
|
-
end
|
171
|
-
|
172
|
-
# Set the defaults when this class responds to the same method
|
173
|
-
self.send("#{method_name}=".to_sym, v) if v and self.respond_to?("#{method_name}=")
|
174
|
-
@mutex_in_call_for.delete method_name
|
175
|
-
@proxied_with_nil << method_name if v == nil
|
146
|
+
|
147
|
+
return v if v or @mutex_in_call_for.include? method_name
|
148
|
+
|
149
|
+
# Track fallbacks that were used to prevent reusing them (on nil results)
|
150
|
+
@fallbacks_used ||= []
|
151
|
+
|
152
|
+
@mutex_in_call_for << method_name
|
153
|
+
fallback_method = "_run_fallback_#{method_name}".to_sym
|
154
|
+
|
155
|
+
custom_fallback = !!self.respond_to?(fallback_method)
|
156
|
+
|
157
|
+
if custom_fallback and not @fallbacks_used.include? method_name
|
158
|
+
send_args = [fallback_method]
|
159
|
+
|
160
|
+
if self.method(fallback_method).arity == 1
|
161
|
+
def_fallback_obj = self.class.instance_variable_get(:@fallback_fetch)[self]
|
162
|
+
send_args << def_fallback_obj
|
176
163
|
end
|
164
|
+
|
165
|
+
@fallbacks_used << method_name
|
166
|
+
elsif not custom_fallback and not @fallbacks_used.include? "default"
|
167
|
+
args_class = ArgsClass.new(self)
|
168
|
+
self.class.send :run_fallback, args_class, self
|
169
|
+
|
170
|
+
# The value might have changed, so check here
|
171
|
+
send_args = ["no_proxy_#{method_name}".to_sym]
|
177
172
|
end
|
178
173
|
|
174
|
+
v = self.send(*send_args) if send_args
|
175
|
+
self.send("#{method_name}=", v) if v and custom_fallback
|
176
|
+
|
177
|
+
@mutex_in_call_for.delete method_name
|
178
|
+
|
179
179
|
return v
|
180
180
|
end
|
181
181
|
end
|
data/lib/classproxy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classproxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
segments:
|
57
57
|
- 0
|
58
|
-
hash:
|
58
|
+
hash: 4292062125243111746
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
60
|
none: false
|
61
61
|
requirements:
|