overridable 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/overridable.rb +5 -0
- data/test/overridable_test.rb +30 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/lib/overridable.rb
CHANGED
@@ -163,10 +163,15 @@ module Overridable
|
|
163
163
|
|
164
164
|
old_verbose, $VERBOSE = $VERBOSE, nil # supress warnings
|
165
165
|
methods.each { |m|
|
166
|
+
scope = private_instance_methods(false).include?(m.name) ?
|
167
|
+
:private :
|
168
|
+
protected_instance_methods(false).include?(m.name) ?
|
169
|
+
:protected : :public
|
166
170
|
remove_method m.name
|
167
171
|
mod.send :define_method, m.name do |*args, &blk|
|
168
172
|
m.bind(self).call(*args, &blk)
|
169
173
|
end
|
174
|
+
mod.send scope, m.name
|
170
175
|
}
|
171
176
|
$VERBOSE = old_verbose
|
172
177
|
end
|
data/test/overridable_test.rb
CHANGED
@@ -161,4 +161,34 @@ context "a classes with some methods defined in it" do
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
+
context "there are also some protected and private methods in it." do
|
165
|
+
setup {
|
166
|
+
topic.class_eval {
|
167
|
+
protected
|
168
|
+
def protected_method; end
|
169
|
+
private
|
170
|
+
def private_method; end
|
171
|
+
}
|
172
|
+
topic
|
173
|
+
}
|
174
|
+
|
175
|
+
context "Call overrides on these protected and private methods, it should not change their scope." do
|
176
|
+
setup {
|
177
|
+
topic.class_eval {
|
178
|
+
include Overridable
|
179
|
+
overrides :protected_method, :private_method
|
180
|
+
}
|
181
|
+
topic
|
182
|
+
}
|
183
|
+
|
184
|
+
should("raise exception when call protected_method outside the class.") {
|
185
|
+
topic.new.protected_method
|
186
|
+
}.raises(NoMethodError, /protected method `protected_method' called/)
|
187
|
+
|
188
|
+
should("raise exception when call private_method outside the class.") {
|
189
|
+
topic.new.private_method
|
190
|
+
}.raises(NoMethodError, /private method `private_method' called/)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
164
194
|
end
|