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 CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overridable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "\xE6\xA2\x81\xE6\x99\xBA\xE6\x95\x8F(Gimi Liang)"