methodfinalizer 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/final_method/final_method.rb +28 -2
- data/lib/final_method/final_method_version.rb +1 -1
- data/test/test_method_finalizer_usage.rb +38 -12
- metadata +2 -2
data/History.txt
CHANGED
@@ -139,6 +139,11 @@ module OOP
|
|
139
139
|
end
|
140
140
|
alias_method :get_final_class_methods, :get_final_singleton_methods
|
141
141
|
|
142
|
+
def final_singleton_method_exists?(method)
|
143
|
+
final_method_exists?(@@final_singleton_methods, method)
|
144
|
+
end
|
145
|
+
alias_method :final_class_method_exists?, :final_singleton_method_exists?
|
146
|
+
|
142
147
|
# :stopdoc:
|
143
148
|
def singleton_method_added(method_name)
|
144
149
|
__method_added__(@@final_singleton_methods, method_name, 'class')
|
@@ -225,6 +230,10 @@ module OOP
|
|
225
230
|
get_final_methods(@@final_instance_methods, sorted)
|
226
231
|
end
|
227
232
|
|
233
|
+
def final_instance_method_exists?(method)
|
234
|
+
final_method_exists?(@@final_instance_methods, method)
|
235
|
+
end
|
236
|
+
|
228
237
|
private
|
229
238
|
def final_methods(final_methods, method_names, method_type = 'class')
|
230
239
|
validations = validate_methods(final_methods, method_names, self)
|
@@ -309,7 +318,7 @@ module OOP
|
|
309
318
|
|
310
319
|
def get_final_methods(final_methods, sorted=false)
|
311
320
|
fm = []
|
312
|
-
get_subclass_range
|
321
|
+
get_subclass_range.each do |_class|
|
313
322
|
if final_methods[_class]
|
314
323
|
final_methods[_class].each do |method|
|
315
324
|
fm.concat method.keys
|
@@ -320,7 +329,7 @@ module OOP
|
|
320
329
|
fm
|
321
330
|
end
|
322
331
|
|
323
|
-
def get_subclass_range
|
332
|
+
def get_subclass_range
|
324
333
|
_ancestors = self.ancestors
|
325
334
|
_ancestors.each do |a|
|
326
335
|
if self.eql?(a)
|
@@ -331,10 +340,27 @@ module OOP
|
|
331
340
|
end
|
332
341
|
_ancestors
|
333
342
|
end
|
343
|
+
|
344
|
+
def final_method_exists?(final_methods, method)
|
345
|
+
raise_error_when_argument_not_symbol(method)
|
346
|
+
ret, subclass_range = false, get_subclass_range
|
347
|
+
final_methods.each do |key,value|
|
348
|
+
if subclass_range.include?(key)
|
349
|
+
value.each do |m|
|
350
|
+
return true if m.has_key?(method)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
ret
|
355
|
+
end
|
334
356
|
|
335
357
|
def raise_error_when_method_names_empty_or_nil(method_names)
|
336
358
|
raise ArgumentError.new("methods arguments missing.") if (method_names.empty? || method_names.nil?)
|
337
359
|
end
|
360
|
+
|
361
|
+
def raise_error_when_argument_not_symbol(method)
|
362
|
+
raise ArgumentError.new("incorrect method argument type. It must be symbol") unless method.is_a?(Symbol)
|
363
|
+
end
|
338
364
|
end
|
339
365
|
end
|
340
366
|
end
|
@@ -2,18 +2,6 @@ require 'test/unit'
|
|
2
2
|
require 'test_classes_files/method_finalizer_usage'
|
3
3
|
|
4
4
|
class TestMethodFinalizerUsage < Test::Unit::TestCase
|
5
|
-
def test_get_final_singleton_methods
|
6
|
-
assert Bb.respond_to?(:get_final_singleton_methods)
|
7
|
-
assert_equal [:m_five, :m_one, :m_six, :m_two], Bb.get_final_singleton_methods(true)
|
8
|
-
assert_equal [:m_one, :m_two], Aa.get_final_singleton_methods(true)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_get_final_instance_methods
|
12
|
-
assert Bb.respond_to?(:get_final_instance_methods)
|
13
|
-
assert_equal [:m_eight, :m_four, :m_seven, :m_three], Bb.get_final_instance_methods(true)
|
14
|
-
assert_equal [:m_four, :m_three], Aa.get_final_instance_methods(true)
|
15
|
-
end
|
16
|
-
|
17
5
|
def test_final_class_methods
|
18
6
|
assert_equal "'m_one' in Aa", Aa.m_one
|
19
7
|
assert_equal "'m_two' in Aa", Aa.m_two
|
@@ -31,4 +19,42 @@ class TestMethodFinalizerUsage < Test::Unit::TestCase
|
|
31
19
|
assert_equal "'m_seven' in Bb", Bb.new.m_seven
|
32
20
|
assert_equal "'m_eight' in Bb", Bb.new.m_eight
|
33
21
|
end
|
22
|
+
|
23
|
+
def test_get_final_singleton_methods
|
24
|
+
assert Bb.respond_to?(:get_final_singleton_methods)
|
25
|
+
assert_equal [:m_five, :m_one, :m_six, :m_two], Bb.get_final_singleton_methods(true)
|
26
|
+
assert_equal [:m_one, :m_two], Aa.get_final_singleton_methods(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_get_final_instance_methods
|
30
|
+
assert Bb.respond_to?(:get_final_instance_methods)
|
31
|
+
assert_equal [:m_eight, :m_four, :m_seven, :m_three], Bb.get_final_instance_methods(true)
|
32
|
+
assert_equal [:m_four, :m_three], Aa.get_final_instance_methods(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_singleton_method_exist
|
36
|
+
assert Bb.respond_to?(:final_singleton_method_exists?)
|
37
|
+
assert Bb.respond_to?(:final_class_method_exists?)
|
38
|
+
assert_raises ArgumentError do
|
39
|
+
Bb.final_singleton_method_exists?("m_five")
|
40
|
+
end
|
41
|
+
assert_raises ArgumentError do
|
42
|
+
Bb.final_singleton_method_exists?
|
43
|
+
end
|
44
|
+
assert Bb.final_singleton_method_exists?(:m_five)
|
45
|
+
assert !Aa.final_singleton_method_exists?(:m_five)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_instance_method_exist
|
49
|
+
assert Bb.respond_to?(:final_instance_method_exists?)
|
50
|
+
assert_raises ArgumentError do
|
51
|
+
Bb.final_instance_method_exists?("m_three")
|
52
|
+
end
|
53
|
+
assert_raises ArgumentError do
|
54
|
+
Bb.final_instance_method_exists?
|
55
|
+
end
|
56
|
+
assert Bb.final_instance_method_exists?(:m_three)
|
57
|
+
assert !Aa.final_instance_method_exists?(:m_seven)
|
58
|
+
assert !Bb.final_instance_method_exists?(:m_ten)
|
59
|
+
end
|
34
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: methodfinalizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wilfrido T. Nuqui Jr.
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-24 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|