methodfinalizer 0.6.0 → 0.7.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 +6 -1
- data/Manifest.txt +5 -0
- data/Rakefile +1 -0
- data/lib/final_method/final_method.rb +39 -10
- data/lib/final_method/final_method_exceptions.rb +10 -0
- data/lib/final_method/final_method_version.rb +1 -1
- data/test/test_classes_files/final_class_method_files/final_class_method_declared_but_not_defined.rb +10 -0
- data/test/test_classes_files/final_instance_method_files/final_instance_method_declared_but_not_defined.rb +10 -0
- data/test/test_classes_files/special_class_method_redefinition.rb +15 -0
- data/test/test_final_declared_but_not_defined.rb +32 -0
- data/test/test_special_class_method_redefinition.rb +20 -0
- metadata +19 -2
    
        data/History.txt
    CHANGED
    
    | @@ -8,4 +8,9 @@ | |
| 8 8 |  | 
| 9 9 | 
             
            * added 2 methods
         | 
| 10 10 |  | 
| 11 | 
            -
              * added 'final_singleton_method_exists?' and 'final_instance_method_exists?'
         | 
| 11 | 
            +
              * added 'final_singleton_method_exists?' and 'final_instance_method_exists?'
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            === 0.7.0 / 2009-03-26
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            * fixed: #24861 (please see at details at rubyforge)
         | 
| 16 | 
            +
            * resolved handling of special final class method redefinition (see commit message at github for more)
         | 
    
        data/Manifest.txt
    CHANGED
    
    | @@ -7,14 +7,19 @@ lib/methodfinalizer.rb | |
| 7 7 | 
             
            lib/final_method/final_method.rb
         | 
| 8 8 | 
             
            lib/final_method/final_method_version.rb
         | 
| 9 9 | 
             
            lib/final_method/final_method_exceptions.rb
         | 
| 10 | 
            +
            test/test_final_declared_but_not_defined.rb
         | 
| 10 11 | 
             
            test/test_method_finalizer.rb
         | 
| 11 12 | 
             
            test/test_method_finalizer_usage.rb
         | 
| 13 | 
            +
            test/test_special_class_method_redefinition.rb
         | 
| 12 14 | 
             
            test/test_classes_files/method_finalizer_usage.rb
         | 
| 15 | 
            +
            test/test_classes_files/special_class_method_redefinition.rb
         | 
| 13 16 | 
             
            test/test_classes_files/final_class_method_files/final_class_method_called_with_no_method_arguments.rb
         | 
| 17 | 
            +
            test/test_classes_files/final_class_method_files/final_class_method_declared_but_not_defined.rb
         | 
| 14 18 | 
             
            test/test_classes_files/final_class_method_files/redeclared_final_class_methods_in_child.rb
         | 
| 15 19 | 
             
            test/test_classes_files/final_class_method_files/redefined_final_class_method_in_child_class_using_parent.rb
         | 
| 16 20 | 
             
            test/test_classes_files/final_class_method_files/redefined_final_class_method_in_child_class.rb
         | 
| 17 21 | 
             
            test/test_classes_files/final_instance_method_files/final_instance_method_called_with_no_method_arguments.rb
         | 
| 22 | 
            +
            test/test_classes_files/final_instance_method_files/final_instance_method_declared_but_not_defined.rb
         | 
| 18 23 | 
             
            test/test_classes_files/final_instance_method_files/redeclared_final_instance_methods_in_child.rb
         | 
| 19 24 | 
             
            test/test_classes_files/final_instance_method_files/redefined_final_instance_method_in_child_instance_using_parent.rb
         | 
| 20 25 | 
             
            test/test_classes_files/final_instance_method_files/redefined_final_instance_method_in_child_class.rb
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -3,6 +3,7 @@ require 'hoe' | |
| 3 3 | 
             
            require 'lib/methodfinalizer'
         | 
| 4 4 |  | 
| 5 5 | 
             
            Hoe.new('methodfinalizer', OOP::Concepts::FinalMethod::FINAL_METHOD_VERSION) do |p|
         | 
| 6 | 
            +
              p.extra_deps << ['ruby2ruby', '= 1.2.2']
         | 
| 6 7 | 
             
              p.rubyforge_name = 'methodfinalizer'
         | 
| 7 8 | 
             
              p.developer('Wilfrido T. Nuqui Jr.', 'dofreewill22@gmail.com')
         | 
| 8 9 | 
             
            end
         | 
| @@ -1,4 +1,6 @@ | |
| 1 1 | 
             
            require File.dirname(__FILE__) + '/final_method_version'
         | 
| 2 | 
            +
            require 'rubygems'
         | 
| 3 | 
            +
            require 'ruby2ruby'
         | 
| 2 4 |  | 
| 3 5 | 
             
            module OOP
         | 
| 4 6 | 
             
              module Concepts
         | 
| @@ -239,10 +241,11 @@ module OOP | |
| 239 241 | 
             
                      validations = validate_methods(final_methods, method_names, self)
         | 
| 240 242 | 
             
                      if(validations[:valid])
         | 
| 241 243 | 
             
                        if final_methods.has_key?(self) && ((final_methods[self] - method_names) == final_methods[self])
         | 
| 242 | 
            -
                          final_methods[self].concat(method_names.collect{|method_name| {method_name => 0}})
         | 
| 244 | 
            +
                          final_methods[self].concat(method_names.collect{|method_name| {method_name => {:definition_count => 0, :definition_str => nil}}})
         | 
| 243 245 | 
             
                        else
         | 
| 244 | 
            -
                          final_methods[self] = method_names.collect{|method_name| {method_name => 0}}
         | 
| 246 | 
            +
                          final_methods[self] = method_names.collect{|method_name| {method_name => {:definition_count => 0, :definition_str => nil}}}
         | 
| 245 247 | 
             
                        end
         | 
| 248 | 
            +
                        nil # must return nil
         | 
| 246 249 | 
             
                      else
         | 
| 247 250 | 
             
                        final_method_error = method_type.eql?('class') ? FinalClassMethodRedeclarationError : FinalInstanceMethodRedeclarationError
         | 
| 248 251 | 
             
                        raise final_method_error.new(validations[:error_message])
         | 
| @@ -258,15 +261,23 @@ module OOP | |
| 258 261 | 
             
                        else
         | 
| 259 262 | 
             
                          remove_method method_name
         | 
| 260 263 | 
             
                        end
         | 
| 261 | 
            -
                         | 
| 262 | 
            -
             | 
| 264 | 
            +
                        unless get_first_final_method_definition(parent, final_methods, method_name).nil? # defined here
         | 
| 265 | 
            +
                          final_method_error = method_type.eql?('class') ? FinalClassMethodRedefinitionError : FinalInstanceMethodRedefinitionError
         | 
| 266 | 
            +
                          raise final_method_error.new("cannot redefine '#{method_name}' because it is already defined as final #{method_type} method in parent #{parent}.")
         | 
| 267 | 
            +
                        else
         | 
| 268 | 
            +
                          final_method_error = method_type.eql?('class') ? FinalClassMethodEmptyDefinitionError : FinalInstanceMethodEmptyDefinitionError
         | 
| 269 | 
            +
                          raise final_method_error.new("'#{method_name}' is declared but not defined as final #{method_type} method in parent #{parent} and was attempted to be redefined in child #{self}.")
         | 
| 270 | 
            +
                        end
         | 
| 271 | 
            +
                            
         | 
| 263 272 | 
             
                      else
         | 
| 264 273 | 
             
                        unless(parent = get_class_of_final_method(final_methods, method_name, true)).nil?
         | 
| 265 274 | 
             
                          increment_final_method_definition_count(final_methods[parent], method_name)
         | 
| 266 | 
            -
                          if((final_method_definition_count(final_methods[parent], method_name))  | 
| 267 | 
            -
                             | 
| 268 | 
            -
             | 
| 269 | 
            -
                             | 
| 275 | 
            +
                          if((fmd_count = final_method_definition_count(final_methods[parent], method_name)) == 1)
         | 
| 276 | 
            +
                            store_first_final_method_definition(parent, final_methods, method_name, method_type)
         | 
| 277 | 
            +
                          elsif (fmd_count > 1) && method_type.eql?('class')
         | 
| 278 | 
            +
                            reset_final_method_definition_count(final_methods[parent], method_name)
         | 
| 279 | 
            +
                            class_eval get_first_final_method_definition(parent, final_methods, method_name)
         | 
| 280 | 
            +
                            raise FinalClassMethodRedefinitionError.new("cannot redefine '#{method_name}' because it is already defined as final class method in parent #{parent}.")
         | 
| 270 281 | 
             
                          end
         | 
| 271 282 | 
             
                        end
         | 
| 272 283 | 
             
                      end
         | 
| @@ -290,13 +301,31 @@ module OOP | |
| 290 301 |  | 
| 291 302 | 
             
                    def increment_final_method_definition_count(method_names, method_name)
         | 
| 292 303 | 
             
                      method_names.each do |mn|
         | 
| 293 | 
            -
                        mn[method_name] +=1 if mn.has_key?(method_name)
         | 
| 304 | 
            +
                        mn[method_name][:definition_count] +=1 if mn.has_key?(method_name)
         | 
| 294 305 | 
             
                      end
         | 
| 295 306 | 
             
                    end
         | 
| 296 307 |  | 
| 297 308 | 
             
                    def final_method_definition_count(method_names, method_name)
         | 
| 298 309 | 
             
                      method_names.each do |mn|
         | 
| 299 | 
            -
                        return mn[method_name] if mn.has_key?(method_name)
         | 
| 310 | 
            +
                        return mn[method_name][:definition_count] if mn.has_key?(method_name)
         | 
| 311 | 
            +
                      end
         | 
| 312 | 
            +
                    end
         | 
| 313 | 
            +
                    
         | 
| 314 | 
            +
                    def store_first_final_method_definition(context, final_methods, method_name, method_type)
         | 
| 315 | 
            +
                      final_methods[context].each do |mn|
         | 
| 316 | 
            +
                        mn[method_name][:definition_str] = "#{Ruby2Ruby.translate context, "#{"self." if method_type.eql?('class')}#{method_name}"}" if mn.has_key?(method_name)
         | 
| 317 | 
            +
                      end
         | 
| 318 | 
            +
                    end
         | 
| 319 | 
            +
                    
         | 
| 320 | 
            +
                    def get_first_final_method_definition(context, final_methods, method_name)
         | 
| 321 | 
            +
                      final_methods[context].each do |mn|
         | 
| 322 | 
            +
                        return mn[method_name][:definition_str] if mn.has_key?(method_name)
         | 
| 323 | 
            +
                      end
         | 
| 324 | 
            +
                    end
         | 
| 325 | 
            +
                    
         | 
| 326 | 
            +
                    def reset_final_method_definition_count(method_names, method_name)
         | 
| 327 | 
            +
                      method_names.each do |mn|
         | 
| 328 | 
            +
                        mn[method_name][:definition_count] = 0 if mn.has_key?(method_name)
         | 
| 300 329 | 
             
                      end
         | 
| 301 330 | 
             
                    end
         | 
| 302 331 |  | 
| @@ -20,4 +20,14 @@ end | |
| 20 20 | 
             
            # Raised when final instance method declared in parent class
         | 
| 21 21 | 
             
            # is attempted to be redeclared in child class as final instance method.
         | 
| 22 22 | 
             
            class FinalInstanceMethodRedeclarationError < FinalMethodError
         | 
| 23 | 
            +
            end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            # Raised when final class method is declared but not defined in parent class
         | 
| 26 | 
            +
            # and is attempted to be defined in child class
         | 
| 27 | 
            +
            class FinalClassMethodEmptyDefinitionError < FinalMethodError
         | 
| 28 | 
            +
            end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            # Raised when final instance method is declared but not defined in parent class
         | 
| 31 | 
            +
            # and is attempted to be defined in child class
         | 
| 32 | 
            +
            class FinalInstanceMethodEmptyDefinitionError < FinalMethodError
         | 
| 23 33 | 
             
            end
         | 
| @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            require 'test/unit'
         | 
| 2 | 
            +
            require 'final_method/final_method_exceptions'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class TestFinalDeclaredButNotDefined < Test::Unit::TestCase
         | 
| 5 | 
            +
              def test_final_class_method_called_with_no_method_arguments
         | 
| 6 | 
            +
                assert_raises FinalClassMethodEmptyDefinitionError do
         | 
| 7 | 
            +
                  require "test_classes_files/final_class_method_files/final_class_method_declared_but_not_defined"
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
              
         | 
| 11 | 
            +
              def test_final_instance_method_called_with_no_method_arguments
         | 
| 12 | 
            +
                assert_raises FinalInstanceMethodEmptyDefinitionError do
         | 
| 13 | 
            +
                  require "test_classes_files/final_instance_method_files/final_instance_method_declared_but_not_defined"
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
              
         | 
| 17 | 
            +
              def test_final_class_method_called_with_no_method_arguments_with_rescue
         | 
| 18 | 
            +
                begin
         | 
| 19 | 
            +
                  require "test_classes_files/final_class_method_files/final_class_method_declared_but_not_defined"
         | 
| 20 | 
            +
                rescue
         | 
| 21 | 
            +
                  assert !ChowChow.respond_to?(:increase_breed_type)
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
              
         | 
| 25 | 
            +
              def test_final_instance_method_called_with_no_method_arguments_with_rescue
         | 
| 26 | 
            +
                begin
         | 
| 27 | 
            +
                  require "test_classes_files/final_instance_method_files/final_instance_method_declared_but_not_defined"
         | 
| 28 | 
            +
                rescue
         | 
| 29 | 
            +
                  assert !ChowChow.new.respond_to?(:wiggle)
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
            end
         | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require 'test/unit'
         | 
| 2 | 
            +
            require 'methodfinalizer'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class TestSpecialClassMethodRedefinition < Test::Unit::TestCase
         | 
| 5 | 
            +
              def test_require_without_rescue
         | 
| 6 | 
            +
                assert_raises FinalClassMethodRedefinitionError do
         | 
| 7 | 
            +
                  require "test_classes_files/special_class_method_redefinition"
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
              
         | 
| 11 | 
            +
              def test_require_with_rescue
         | 
| 12 | 
            +
                begin
         | 
| 13 | 
            +
                  require "test_classes_files/special_class_method_redefinition"
         | 
| 14 | 
            +
                rescue
         | 
| 15 | 
            +
                  assert_equal "aw aw aw!", Dog.bark # redefinition is handled by 'methodfinalizer'
         | 
| 16 | 
            +
                  assert_equal "aw aw aw!", ChowChow.bark
         | 
| 17 | 
            +
                  assert_not_equal "meow meow meow!", ChowChow.bark
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            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.7.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Wilfrido T. Nuqui Jr.
         | 
| @@ -9,9 +9,19 @@ autorequire: | |
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 |  | 
| 12 | 
            -
            date: 2009-03- | 
| 12 | 
            +
            date: 2009-03-26 00:00:00 +08:00
         | 
| 13 13 | 
             
            default_executable: 
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 16 | 
            +
              name: ruby2ruby
         | 
| 17 | 
            +
              type: :runtime
         | 
| 18 | 
            +
              version_requirement: 
         | 
| 19 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 20 | 
            +
                requirements: 
         | 
| 21 | 
            +
                - - "="
         | 
| 22 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 23 | 
            +
                    version: 1.2.2
         | 
| 24 | 
            +
                version: 
         | 
| 15 25 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 16 26 | 
             
              name: hoe
         | 
| 17 27 | 
             
              type: :development
         | 
| @@ -44,14 +54,19 @@ files: | |
| 44 54 | 
             
            - lib/final_method/final_method.rb
         | 
| 45 55 | 
             
            - lib/final_method/final_method_version.rb
         | 
| 46 56 | 
             
            - lib/final_method/final_method_exceptions.rb
         | 
| 57 | 
            +
            - test/test_final_declared_but_not_defined.rb
         | 
| 47 58 | 
             
            - test/test_method_finalizer.rb
         | 
| 48 59 | 
             
            - test/test_method_finalizer_usage.rb
         | 
| 60 | 
            +
            - test/test_special_class_method_redefinition.rb
         | 
| 49 61 | 
             
            - test/test_classes_files/method_finalizer_usage.rb
         | 
| 62 | 
            +
            - test/test_classes_files/special_class_method_redefinition.rb
         | 
| 50 63 | 
             
            - test/test_classes_files/final_class_method_files/final_class_method_called_with_no_method_arguments.rb
         | 
| 64 | 
            +
            - test/test_classes_files/final_class_method_files/final_class_method_declared_but_not_defined.rb
         | 
| 51 65 | 
             
            - test/test_classes_files/final_class_method_files/redeclared_final_class_methods_in_child.rb
         | 
| 52 66 | 
             
            - test/test_classes_files/final_class_method_files/redefined_final_class_method_in_child_class_using_parent.rb
         | 
| 53 67 | 
             
            - test/test_classes_files/final_class_method_files/redefined_final_class_method_in_child_class.rb
         | 
| 54 68 | 
             
            - test/test_classes_files/final_instance_method_files/final_instance_method_called_with_no_method_arguments.rb
         | 
| 69 | 
            +
            - test/test_classes_files/final_instance_method_files/final_instance_method_declared_but_not_defined.rb
         | 
| 55 70 | 
             
            - test/test_classes_files/final_instance_method_files/redeclared_final_instance_methods_in_child.rb
         | 
| 56 71 | 
             
            - test/test_classes_files/final_instance_method_files/redefined_final_instance_method_in_child_instance_using_parent.rb
         | 
| 57 72 | 
             
            - test/test_classes_files/final_instance_method_files/redefined_final_instance_method_in_child_class.rb
         | 
| @@ -83,5 +98,7 @@ signing_key: | |
| 83 98 | 
             
            specification_version: 2
         | 
| 84 99 | 
             
            summary: "'methodfinalizer' is a gem that allows you to declare final class and instance methods in your ruby program."
         | 
| 85 100 | 
             
            test_files: 
         | 
| 101 | 
            +
            - test/test_final_declared_but_not_defined.rb
         | 
| 102 | 
            +
            - test/test_special_class_method_redefinition.rb
         | 
| 86 103 | 
             
            - test/test_method_finalizer_usage.rb
         | 
| 87 104 | 
             
            - test/test_method_finalizer.rb
         |