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