method_finalizer 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-03-17
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,17 @@
1
+ History.txt
2
+ Manifest.txt
3
+ Rakefile
4
+ README.txt
5
+ lib/method_finalizer.rb
6
+ lib/final_method/final_method.rb
7
+ lib/final_method/final_method_version.rb
8
+ lib/final_method/final_method_exceptions.rb
9
+ test/test_method_finalizer.rb
10
+ test/test_method_finalizer_usage.rb
11
+ test/test_classes_files/method_finalizer_usage.rb
12
+ test/test_classes_files/final_class_method_files/redeclared_final_class_methods_in_child.rb
13
+ test/test_classes_files/final_class_method_files/redefined_final_class_method_in_child_class_using_parent.rb
14
+ test/test_classes_files/final_class_method_files/redefined_final_class_method_in_child_class.rb
15
+ test/test_classes_files/final_instance_method_files/redeclared_final_instance_methods_in_child.rb
16
+ test/test_classes_files/final_instance_method_files/redefined_final_instance_method_in_child_instance_using_parent.rb
17
+ test/test_classes_files/final_instance_method_files/redefined_final_instance_method_in_child_class.rb
data/README.txt ADDED
@@ -0,0 +1,101 @@
1
+ == method_finalizer
2
+
3
+ by Wilfrido T. Nuqui Jr.
4
+ dofreewill22@gmail.com
5
+ wnuqui@exist.com
6
+
7
+ == DESCRIPTION:
8
+
9
+ 'method_finalizer' is a gem that allows you to declare final class and instance methods in your ruby program.
10
+
11
+ == FEATURES:
12
+
13
+ can declare
14
+ final class method(s), or
15
+ final instance method(s),
16
+ implement it and feel safe they will not be redefined
17
+
18
+ == SYNOPSIS:
19
+
20
+ Require 'rubygems' and 'method_finalizer' gems.
21
+
22
+ require 'rubygems'
23
+ require 'method_finalizer'
24
+
25
+ class A
26
+ # declare your final class and instance methods
27
+ final_class_method :method_one
28
+ final_instance_methods :method_two, :method_three
29
+
30
+ def A.method_one
31
+ "'method_one' class method in A declared as final"
32
+ end
33
+
34
+ def method_two
35
+ "'method_two' instance method in A declared as final"
36
+ end
37
+
38
+ def method_three
39
+ "'method_three' instance method in A declared as final"
40
+ end
41
+ end
42
+
43
+ Now,
44
+
45
+ class B < A
46
+ # attempting to redeclare 'method_one' as final class method
47
+ final_class_method :method_one
48
+ end
49
+
50
+ will yield this error
51
+
52
+ FinalClassMethodRedeclarationError: cannot declare 'method_one' as final method in child B as parent A declared it already as such
53
+
54
+ and when,
55
+
56
+ class B < A
57
+ # attempting to redefine 'method_one'
58
+ def self.method_one
59
+ "'method_one' class method in B"
60
+ end
61
+ end
62
+
63
+ will give you
64
+
65
+ FinalClassMethodRedefinitionError: cannot redefine 'method_one' because it is already defined as final class method in parent A.
66
+
67
+
68
+ == REQUIREMENTS:
69
+
70
+ * rake
71
+ * rubyforge
72
+ * rubygems
73
+
74
+ == INSTALL:
75
+
76
+ * sudo gem install method_finalizer
77
+
78
+ == LICENSE:
79
+
80
+ (The MIT License)
81
+
82
+ Copyright (c) 2009 Wilfrido T. Nuqui Jr.
83
+
84
+ Permission is hereby granted, free of charge, to any person obtaining
85
+ a copy of this software and associated documentation files (the
86
+ 'Software'), to deal in the Software without restriction, including
87
+ without limitation the rights to use, copy, modify, merge, publish,
88
+ distribute, sublicense, and/or sell copies of the Software, and to
89
+ permit persons to whom the Software is furnished to do so, subject to
90
+ the following conditions:
91
+
92
+ The above copyright notice and this permission notice shall be
93
+ included in all copies or substantial portions of the Software.
94
+
95
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
96
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
97
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
98
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
99
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
100
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
101
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ require 'lib/method_finalizer'
4
+
5
+ Hoe.new('method_finalizer', OOP::Concepts::FinalMethod::FINAL_METHOD_VERSION) do |p|
6
+ p.rubyforge_name = 'method_finalizer'
7
+ p.developer('Wilfrido T. Nuqui Jr.', 'dofreewill22@gmail.com')
8
+ end
@@ -0,0 +1,335 @@
1
+ require File.dirname(__FILE__) + '/final_method_version'
2
+
3
+ module OOP
4
+ module Concepts
5
+ ##
6
+ # 'method_finalizer' is a gem that allows you to declare final class and instance methods in your ruby program.
7
+ #
8
+ # == Using 'method_finalizer'
9
+ #
10
+ # === Basics
11
+ #
12
+ # Require 'rubygems' and 'method_finalizer' gems.
13
+ #
14
+ # require 'rubygems'
15
+ # require 'method_finalizer'
16
+ #
17
+ # class A
18
+ # # declare your final class and instance methods
19
+ # final_class_method :method_one
20
+ # final_instance_methods :method_two, :method_three
21
+ #
22
+ # def A.method_one
23
+ # "'method_one' class method in A declared as final"
24
+ # end
25
+ #
26
+ # def method_two
27
+ # "'method_two' instance method in A declared as final"
28
+ # end
29
+ #
30
+ # def method_three
31
+ # "'method_three' instance method in A declared as final"
32
+ # end
33
+ # end
34
+ #
35
+ # Now,
36
+ #
37
+ # class B < A
38
+ # # attempting to redeclare 'method_one' as final class method
39
+ # final_class_method :method_one
40
+ # end
41
+ #
42
+ # will yield this error
43
+ #
44
+ # FinalClassMethodRedeclarationError: cannot declare 'method_one' as final method in child B as parent A declared it already as such
45
+ #
46
+ # and when,
47
+ #
48
+ # class B < A
49
+ # # attempting to redefine 'method_one'
50
+ # def self.method_one
51
+ # "'method_one' class method in B"
52
+ # end
53
+ # end
54
+ #
55
+ # will give you
56
+ #
57
+ # FinalClassMethodRedefinitionError: cannot redefine 'method_one' because it is already defined as final class method in parent A.
58
+ ##
59
+
60
+ module FinalMethod
61
+ include FinalMethodVersion
62
+ @@final_singleton_methods, @@final_instance_methods = {}, {}
63
+
64
+ ##
65
+ # This will set a class method as final.
66
+ #
67
+ # class A
68
+ # final_class_method :method_one
69
+ # def self.method_one
70
+ # "final class method 'method_one'"
71
+ # end
72
+ # end
73
+ #
74
+ # Attempting to redeclare it as final class method in subclass,
75
+ #
76
+ # class B < A
77
+ # final_class_method :method_one
78
+ # end
79
+ #
80
+ # will give you
81
+ #
82
+ # FinalClassMethodRedeclarationError: cannot declare 'method_one' as final method in child B as parent A declared it already as such
83
+ #
84
+ # and when,
85
+ #
86
+ # class B < A
87
+ # def B.method_one
88
+ # "'method_one' class method in B"
89
+ # end
90
+ # end
91
+ #
92
+ # will give you
93
+ #
94
+ # FinalClassMethodRedefinitionError: cannot redefine 'method_one' because it is already defined as final class method in parent A.
95
+ ##
96
+ def final_class_methods(*method_names)
97
+ final_methods(@@final_singleton_methods, method_names, 'class')
98
+ end
99
+ alias_method :final_class_method, :final_class_methods
100
+ alias_method :final_singleton_methods, :final_class_methods
101
+ alias_method :final_singleton_method, :final_class_methods
102
+
103
+ ##
104
+ # Returns all final singleton (class) methods. Accepts optional parameter for sorting.
105
+ #
106
+ # class A
107
+ # final_singleton_methods :method_one, :method_two
108
+ # def self.method_one
109
+ # # any code goes here
110
+ # end
111
+ # def self.method_two
112
+ # # any code goes here again
113
+ # end
114
+ # end
115
+ #
116
+ # class B < A
117
+ # final_class_method :method_three
118
+ # def self.method_three
119
+ # end
120
+ # end
121
+ #
122
+ # B.get_final_singleton_methods
123
+ #
124
+ # will give you
125
+ #
126
+ # [:method_one, :method_two, :method_three] # order is random
127
+ #
128
+ # if you will provide sort parameter, like
129
+ #
130
+ # B.get_final_singleton_methods(true) # sort is true
131
+ #
132
+ # you will get
133
+ #
134
+ # [:method_one, :method_three, :method_two]
135
+ ##
136
+ def get_final_singleton_methods(sorted=false)
137
+ get_final_methods(@@final_singleton_methods, sorted)
138
+ end
139
+ alias_method :get_final_class_methods, :get_final_singleton_methods
140
+
141
+ # :stopdoc:
142
+ def singleton_method_added(method_name)
143
+ __method_added__(@@final_singleton_methods, method_name, 'class')
144
+ end
145
+ # :startdoc:
146
+
147
+ ##
148
+ # This will set an instance method as final.
149
+ #
150
+ # class A
151
+ # final_instance_method :method_two
152
+ # def method_two
153
+ # "final instance method 'method_two'"
154
+ # end
155
+ # end
156
+ #
157
+ # Attempting to redeclare it as final instance method in subclass,
158
+ #
159
+ # class B < A
160
+ # final_instance_method :method_two
161
+ # end
162
+ #
163
+ # will give you
164
+ #
165
+ # FinalInstanceMethodRedeclarationError: cannot declare 'method_two' as final method in child B as parent A declared it already as such
166
+ # and when,
167
+ #
168
+ # class B < A
169
+ # def method_one
170
+ # "'method_one' class method in B"
171
+ # end
172
+ # end
173
+ #
174
+ # will give you
175
+ #
176
+ # FinalInstanceMethodRedefinitionError: cannot redefine 'method_one' because it is already defined as final instance method in parent A.
177
+ ##
178
+ def final_instance_methods(*method_names)
179
+ final_methods(@@final_instance_methods, method_names, 'instance')
180
+ end
181
+ alias_method :final_instance_method, :final_instance_methods
182
+
183
+ # :stopdoc:
184
+ def method_added(method_name)
185
+ __method_added__(@@final_instance_methods, method_name, 'instance')
186
+ end
187
+ # :startdoc:
188
+
189
+ ##
190
+ # Returns all final instance methods. Accepts optional parameter for sorting.
191
+ #
192
+ # class A
193
+ # final_instance_methods :method_one, :method_two
194
+ # def method_one
195
+ # # any code goes here
196
+ # end
197
+ # def method_two
198
+ # # any code goes here again
199
+ # end
200
+ # end
201
+ #
202
+ # class B < A
203
+ # final_instance_method :method_three
204
+ # def method_three
205
+ # end
206
+ # end
207
+ #
208
+ # B.get_final_instance_methods
209
+ #
210
+ # will give you
211
+ #
212
+ # [:method_one, :method_two, :method_three] # order is random
213
+ #
214
+ # if you will provide sort parameter, like
215
+ #
216
+ # B.get_final_instance_methods(true) # sort is true
217
+ #
218
+ # you will get
219
+ #
220
+ # [:method_one, :method_three, :method_two]
221
+ ##
222
+ def get_final_instance_methods(sorted=false)
223
+ get_final_methods(@@final_instance_methods, sorted)
224
+ end
225
+
226
+ private
227
+ def final_methods(final_methods, method_names, method_type = 'class')
228
+ validations = validate_methods(final_methods, method_names, self)
229
+ if(validations[:valid])
230
+ if final_methods.has_key?(self) && ((final_methods[self] - method_names) == final_methods[self])
231
+ final_methods[self].concat(method_names.collect{|method_name| {method_name => 0}})
232
+ else
233
+ final_methods[self] = method_names.collect{|method_name| {method_name => 0}}
234
+ end
235
+ else
236
+ final_method_error = method_type.eql?('class') ? FinalClassMethodRedeclarationError : FinalInstanceMethodRedeclarationError
237
+ raise final_method_error.new(validations[:error_message])
238
+ end
239
+ end
240
+
241
+ def __method_added__(final_methods, method_name, method_type='class')
242
+ # once final method added is added already to parent(not equal self),
243
+ # then remove method in current contetxt (self)
244
+ if (parent = get_class_of_final_method(final_methods, method_name))
245
+ if method_type.eql?("class")
246
+ eval %Q{class << #{self}\nremove_method "#{method_name}"\nend}
247
+ else
248
+ remove_method method_name
249
+ end
250
+ final_method_error = method_type.eql?('class') ? FinalClassMethodRedefinitionError : FinalInstanceMethodRedefinitionError
251
+ raise final_method_error.new("cannot redefine '#{method_name}' because it is already defined as final #{method_type} method in parent #{parent}.")
252
+ else
253
+ unless(parent = get_class_of_final_method(final_methods, method_name, true)).nil?
254
+ increment_final_method_definition_count(final_methods[parent], method_name)
255
+ if((final_method_definition_count(final_methods[parent], method_name)) > 1) && method_type.eql?('class')
256
+ final_method_error = method_type.eql?('class') ? FinalClassMethodRedefinitionError : FinalInstanceMethodRedefinitionError
257
+ raise final_method_error.new("redefining class method '#{method_name}' in same class but inside child class will yield erroneous effect.")
258
+ exit
259
+ end
260
+ end
261
+ end
262
+ end
263
+
264
+ def get_class_of_final_method(final_methods, method_name, equal_to_self = false)
265
+ final_methods.each_key do |key|
266
+ if method_declared_already_as_final?(final_methods[key], method_name) && (equal_to_self ? (key == self) : (key != self))
267
+ return key
268
+ end
269
+ end
270
+ nil
271
+ end
272
+
273
+ def method_declared_already_as_final?(method_names, method_name)
274
+ method_names.each do |mn|
275
+ return true if mn.has_key?(method_name)
276
+ end
277
+ false
278
+ end
279
+
280
+ def increment_final_method_definition_count(method_names, method_name)
281
+ method_names.each do |mn|
282
+ mn[method_name] +=1 if mn.has_key?(method_name)
283
+ end
284
+ end
285
+
286
+ def final_method_definition_count(method_names, method_name)
287
+ method_names.each do |mn|
288
+ return mn[method_name] if mn.has_key?(method_name)
289
+ end
290
+ end
291
+
292
+ def validate_methods(final_methods, methods, context)
293
+ validation = {}
294
+ methods.each do |method|
295
+ validation[method] = get_class_of_final_method(final_methods, method)
296
+ end
297
+
298
+ message_for_invalidity = []
299
+ validation.each do |key, parent|
300
+ if parent
301
+ message_for_invalidity << "cannot declare '#{key}' as final method in child #{context} as parent #{parent} declared it already as such."
302
+ end
303
+ end
304
+
305
+ {:valid => (message_for_invalidity.empty?), :error_message => (message_for_invalidity.empty? ? '' : message_for_invalidity.join("\n"))}
306
+ end
307
+
308
+ def get_final_methods(final_methods, sorted=false)
309
+ fm = []
310
+ get_subclass_range(final_methods).each do |_class|
311
+ if final_methods[_class]
312
+ final_methods[_class].each do |method|
313
+ fm.concat method.keys
314
+ end
315
+ end
316
+ end
317
+ fm.sort!{|a, b| a.to_s <=> b.to_s} if sorted
318
+ fm
319
+ end
320
+
321
+ def get_subclass_range(final_methods)
322
+ _ancestors = self.ancestors
323
+ _ancestors.each do |a|
324
+ if self.eql?(a)
325
+ break
326
+ else
327
+ _ancestors.shift
328
+ end
329
+ end
330
+ _ancestors
331
+ end
332
+
333
+ end
334
+ end
335
+ end
@@ -0,0 +1,23 @@
1
+ # Base error class for FinalMethod module
2
+ class FinalMethodError < StandardError
3
+ end
4
+
5
+ # Raised when final class method defined in parent class
6
+ # is attempted to be redefined in child class as final class method.
7
+ class FinalClassMethodRedefinitionError < FinalMethodError
8
+ end
9
+
10
+ # Raised when final class method declared in parent class
11
+ # is attempted to be redeclared in child class as final class method.
12
+ class FinalClassMethodRedeclarationError < FinalMethodError
13
+ end
14
+
15
+ # Raised when final instance method defined in parent class
16
+ # is attempted to be redefined in child class as final instance method.
17
+ class FinalInstanceMethodRedefinitionError < FinalMethodError
18
+ end
19
+
20
+ # Raised when final instance method declared in parent class
21
+ # is attempted to be redeclared in child class as final instance method.
22
+ class FinalInstanceMethodRedeclarationError < FinalMethodError
23
+ end
@@ -0,0 +1,9 @@
1
+ module OOP
2
+ module Concepts
3
+ module FinalMethodVersion
4
+ MAJOR, MINOR, TINY = 0, 5, 0
5
+
6
+ FINAL_METHOD_VERSION = [MAJOR, MINOR, TINY].join('.')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ require File.dirname(__FILE__) + '/final_method/final_method'
2
+ require File.dirname(__FILE__) + '/final_method/final_method_exceptions'
3
+
4
+ class Object
5
+ extend OOP::Concepts::FinalMethod
6
+ end
@@ -0,0 +1,16 @@
1
+ # 2 final class methods are redeclared as final class methods in child class
2
+ require "method_finalizer"
3
+ class A
4
+ final_class_methods :method_one
5
+ final_class_methods :method_two
6
+ def self.method_one
7
+ "final class method 'method_one' in A"
8
+ end
9
+ def self.method_two
10
+ "final class method 'method_two' in A"
11
+ end
12
+ end
13
+
14
+ class B < A
15
+ final_class_methods :method_one, :method_two
16
+ end
@@ -0,0 +1,14 @@
1
+ # final class method is redefined in child class
2
+ require "method_finalizer"
3
+ class A
4
+ final_class_methods :method_one
5
+ def self.method_one
6
+ "final class method 'method_one' in A"
7
+ end
8
+ end
9
+
10
+ class B < A
11
+ def self.method_one
12
+ "final class method 'method_one' in B"
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # final class method is redefined in child class
2
+ require "method_finalizer"
3
+ class A
4
+ final_class_methods :method_one
5
+ def self.method_one
6
+ "final class method 'method_one' in A"
7
+ end
8
+ end
9
+
10
+ class B < A
11
+ def A.method_one
12
+ "final class method 'method_one' in B"
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # 2 final class methods are redeclared as final class methods in child class
2
+ require "method_finalizer"
3
+ class A
4
+ final_instance_methods :method_one
5
+ final_instance_methods :method_two
6
+ def method_one
7
+ "final instance method 'method_one' in A"
8
+ end
9
+ def method_two
10
+ "final instance method 'method_two' in A"
11
+ end
12
+ end
13
+
14
+ class B < A
15
+ final_instance_methods :method_one, :method_two
16
+ end
@@ -0,0 +1,14 @@
1
+ # final class method is redefined in child class
2
+ require "method_finalizer"
3
+ class A
4
+ final_instance_methods :method_one
5
+ def method_one
6
+ "final class method 'method_one' in A"
7
+ end
8
+ end
9
+
10
+ class B < A
11
+ def method_one
12
+ "final instance method 'method_one' in B"
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # final class method is redefined in child class
2
+ require "method_finalizer"
3
+ class A
4
+ final_instance_methods :method_one
5
+ def method_one
6
+ "final class method 'method_one' in A"
7
+ end
8
+ end
9
+
10
+ class B < A
11
+ def method_one
12
+ "final class method 'method_one' in B"
13
+ end
14
+ end
@@ -0,0 +1,64 @@
1
+ require 'method_finalizer'
2
+
3
+ class Aa
4
+ final_class_methods :m_one, :m_two
5
+ final_instance_methods :m_three, :m_four
6
+
7
+ def self.m_one
8
+ "'m_one' in Aa"
9
+ end
10
+
11
+ def self.m_two
12
+ "'m_two' in Aa"
13
+ end
14
+
15
+ def m_three
16
+ "'m_three' in Aa"
17
+ end
18
+
19
+ def m_four
20
+ "'m_four' in Aa"
21
+ end
22
+ end
23
+
24
+ class Bb < Aa
25
+ begin
26
+ final_class_methods :m_one
27
+ rescue
28
+ final_class_methods :m_five
29
+ end
30
+
31
+ begin
32
+ final_class_methods :m_two
33
+ rescue
34
+ final_class_methods :m_six
35
+ end
36
+
37
+ begin
38
+ final_instance_methods :m_three
39
+ rescue
40
+ final_instance_methods :m_seven
41
+ end
42
+
43
+ begin
44
+ final_instance_methods :m_four
45
+ rescue
46
+ final_instance_methods :m_eight
47
+ end
48
+
49
+ def self.m_five
50
+ "'m_five' in Bb"
51
+ end
52
+
53
+ def self.m_six
54
+ "'m_six' in Bb"
55
+ end
56
+
57
+ def m_seven
58
+ "'m_seven' in Bb"
59
+ end
60
+
61
+ def m_eight
62
+ "'m_eight' in Bb"
63
+ end
64
+ end
@@ -0,0 +1,46 @@
1
+ require "test/unit"
2
+
3
+ class TestMethodFinalizer < Test::Unit::TestCase
4
+ def test_final_method
5
+ require "method_finalizer"
6
+ [:final_class_methods, :final_class_method, :final_instance_methods, :final_instance_method].each do |met|
7
+ assert Object.respond_to?(met)
8
+ end
9
+ end
10
+
11
+ def test_redeclared_final_class_methods_in_child
12
+ assert_raises FinalClassMethodRedeclarationError do
13
+ require "test_classes_files/final_class_method_files/redeclared_final_class_methods_in_child"
14
+ end
15
+ end
16
+
17
+ def test_redefined_final_class_method_in_child_class
18
+ assert_raises FinalClassMethodRedefinitionError do
19
+ require "test_classes_files/final_class_method_files/redefined_final_class_method_in_child_class"
20
+ end
21
+ end
22
+
23
+ def test_redefined_final_class_method_in_child_class_using_parent
24
+ assert_raises FinalClassMethodRedefinitionError do
25
+ require "test_classes_files/final_class_method_files/redefined_final_class_method_in_child_class_using_parent"
26
+ end
27
+ end
28
+
29
+ def test_redeclared_final_instance_methods_in_child
30
+ assert_raises FinalInstanceMethodRedeclarationError do
31
+ require "test_classes_files/final_instance_method_files/redeclared_final_instance_methods_in_child"
32
+ end
33
+ end
34
+
35
+ def test_redefined_final_instance_method_in_child_instance_using_parent
36
+ assert_raises FinalInstanceMethodRedefinitionError do
37
+ require "test_classes_files/final_instance_method_files/redefined_final_instance_method_in_child_instance_using_parent"
38
+ end
39
+ end
40
+
41
+ def test_redefined_final_instance_method_in_child_class
42
+ assert_raises FinalInstanceMethodRedefinitionError do
43
+ require "test_classes_files/final_instance_method_files/redefined_final_instance_method_in_child_class"
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ require 'test/unit'
2
+ require 'test_classes_files/method_finalizer_usage'
3
+
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
+ def test_final_class_methods
18
+ assert_equal "'m_one' in Aa", Aa.m_one
19
+ assert_equal "'m_two' in Aa", Aa.m_two
20
+ assert_equal "'m_one' in Aa", Bb.m_one
21
+ assert_equal "'m_two' in Aa", Bb.m_two
22
+ assert_equal "'m_five' in Bb", Bb.m_five
23
+ assert_equal "'m_six' in Bb", Bb.m_six
24
+ end
25
+
26
+ def test_final_instance_methods
27
+ assert_equal "'m_three' in Aa", Aa.new.m_three
28
+ assert_equal "'m_four' in Aa", Aa.new.m_four
29
+ assert_equal "'m_three' in Aa", Bb.new.m_three
30
+ assert_equal "'m_four' in Aa", Bb.new.m_four
31
+ assert_equal "'m_seven' in Bb", Bb.new.m_seven
32
+ assert_equal "'m_eight' in Bb", Bb.new.m_eight
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: method_finalizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Wilfrido T. Nuqui Jr.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-23 00:00:00 +08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.10.0
24
+ version:
25
+ description: "'method_finalizer' is a gem that allows you to declare final class and instance methods in your ruby program."
26
+ email:
27
+ - dofreewill22@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - Rakefile
40
+ - README.txt
41
+ - lib/method_finalizer.rb
42
+ - lib/final_method/final_method.rb
43
+ - lib/final_method/final_method_version.rb
44
+ - lib/final_method/final_method_exceptions.rb
45
+ - test/test_method_finalizer.rb
46
+ - test/test_method_finalizer_usage.rb
47
+ - test/test_classes_files/method_finalizer_usage.rb
48
+ - test/test_classes_files/final_class_method_files/redeclared_final_class_methods_in_child.rb
49
+ - test/test_classes_files/final_class_method_files/redefined_final_class_method_in_child_class_using_parent.rb
50
+ - test/test_classes_files/final_class_method_files/redefined_final_class_method_in_child_class.rb
51
+ - test/test_classes_files/final_instance_method_files/redeclared_final_instance_methods_in_child.rb
52
+ - test/test_classes_files/final_instance_method_files/redefined_final_instance_method_in_child_instance_using_parent.rb
53
+ - test/test_classes_files/final_instance_method_files/redefined_final_instance_method_in_child_class.rb
54
+ has_rdoc: true
55
+ homepage: " by Wilfrido T. Nuqui Jr."
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --main
59
+ - README.txt
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project: method_finalizer
77
+ rubygems_version: 1.3.1
78
+ signing_key:
79
+ specification_version: 2
80
+ summary: "'method_finalizer' is a gem that allows you to declare final class and instance methods in your ruby program."
81
+ test_files:
82
+ - test/test_method_finalizer_usage.rb
83
+ - test/test_method_finalizer.rb