proxy_method 1.2.5 → 1.2.6
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.
- checksums.yaml +4 -4
- data/lib/proxy_method.rb +83 -3
- data/lib/proxy_method/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6f4af87ac13ed1ecd407497936bce7b5e57f16be2348460de75c65c490a756ec
         | 
| 4 | 
            +
              data.tar.gz: 344cc71d86ce1c8af010fe28ef7e8c6040de4237e2673806fbd822595927f684
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 379a2267013b8b47ee6c901a87acac2794103f049651b0eb50743d2deb5477afc14acb0ce94d38b4940ca19dcbf15138745484138e903e1a3ace957beecf1409
         | 
| 7 | 
            +
              data.tar.gz: d54ad49a095ec66ade4d46dfd299f835b651fa09554b79e3c59d98512643c8f1ac4827f9720b7e623e6bd09cb35603a2c6f3fd834a4cd9f63fa8fce6e86b0688
         | 
    
        data/lib/proxy_method.rb
    CHANGED
    
    | @@ -50,7 +50,7 @@ module ProxyMethod | |
| 50 50 | 
             
                #     Dog.create
         | 
| 51 51 | 
             
                #     # => RuntimeError: Disabled!
         | 
| 52 52 | 
             
                #
         | 
| 53 | 
            -
                # You can still access the unproxied version by prefixing ' | 
| 53 | 
            +
                # You can still access the unproxied version by prefixing 'unproxied_'
         | 
| 54 54 | 
             
                # to the method name:
         | 
| 55 55 | 
             
                #
         | 
| 56 56 | 
             
                #     Dog.unproxied_create
         | 
| @@ -74,10 +74,9 @@ module ProxyMethod | |
| 74 74 | 
             
                #       end
         | 
| 75 75 | 
             
                #     end
         | 
| 76 76 | 
             
                #
         | 
| 77 | 
            -
                #     Dog. | 
| 77 | 
            +
                #     Dog.create
         | 
| 78 78 | 
             
                #     # => 'indirectly created'
         | 
| 79 79 |  | 
| 80 | 
            -
             | 
| 81 80 | 
             
                def proxy_class_method(*original_method_names, &proxy_block)
         | 
| 82 81 | 
             
                  options = if original_method_names.last.is_a?(Hash)
         | 
| 83 82 | 
             
                    original_method_names.pop
         | 
| @@ -109,6 +108,87 @@ module ProxyMethod | |
| 109 108 | 
             
                  end
         | 
| 110 109 | 
             
                end
         | 
| 111 110 |  | 
| 111 | 
            +
                ##
         | 
| 112 | 
            +
                # Proxy one or more inherited instance methods, so that they are not used
         | 
| 113 | 
            +
                # directly. Given this base class:
         | 
| 114 | 
            +
                #
         | 
| 115 | 
            +
                #     class Animal
         | 
| 116 | 
            +
                #       def save
         | 
| 117 | 
            +
                #         'saved'
         | 
| 118 | 
            +
                #       end
         | 
| 119 | 
            +
                #
         | 
| 120 | 
            +
                #       def update
         | 
| 121 | 
            +
                #         'updated'
         | 
| 122 | 
            +
                #       end
         | 
| 123 | 
            +
                #     end
         | 
| 124 | 
            +
                #
         | 
| 125 | 
            +
                # The simplest implementation is to pass just a single method name:
         | 
| 126 | 
            +
                #
         | 
| 127 | 
            +
                #     class Dog < Animal
         | 
| 128 | 
            +
                #       proxy_instance_method :save
         | 
| 129 | 
            +
                #     end
         | 
| 130 | 
            +
                #
         | 
| 131 | 
            +
                #     Dog.new.save
         | 
| 132 | 
            +
                #     # => RuntimeError: Disabled by proxy_method
         | 
| 133 | 
            +
                #
         | 
| 134 | 
            +
                #     Dog.new.upate
         | 
| 135 | 
            +
                #     # 'updated'
         | 
| 136 | 
            +
                #
         | 
| 137 | 
            +
                #
         | 
| 138 | 
            +
                # Or use the shorthand form:
         | 
| 139 | 
            +
                #
         | 
| 140 | 
            +
                #     class Dog < Animal
         | 
| 141 | 
            +
                #       proxy_method :save
         | 
| 142 | 
            +
                #     end
         | 
| 143 | 
            +
                #
         | 
| 144 | 
            +
                # Or multiple method names:
         | 
| 145 | 
            +
                #
         | 
| 146 | 
            +
                #     class Dog < Animal
         | 
| 147 | 
            +
                #       proxy_method :save, :update
         | 
| 148 | 
            +
                #     end
         | 
| 149 | 
            +
                #
         | 
| 150 | 
            +
                #     Dog.new.save
         | 
| 151 | 
            +
                #     # => RuntimeError: Disabled by proxy_method
         | 
| 152 | 
            +
                #
         | 
| 153 | 
            +
                #     Dog.new.update
         | 
| 154 | 
            +
                #     # => RuntimeError: Disabled by proxy_method
         | 
| 155 | 
            +
                #
         | 
| 156 | 
            +
                # With a custom error message:
         | 
| 157 | 
            +
                #
         | 
| 158 | 
            +
                #     class Dog < Animal
         | 
| 159 | 
            +
                #       proxy_method :save, raise: 'Disabled!'
         | 
| 160 | 
            +
                #     end
         | 
| 161 | 
            +
                #
         | 
| 162 | 
            +
                #     Dog.new.save
         | 
| 163 | 
            +
                #     # => RuntimeError: Disabled!
         | 
| 164 | 
            +
                #
         | 
| 165 | 
            +
                # You can still access the unproxied version by prefixing 'unproxied_'
         | 
| 166 | 
            +
                # to the method name:
         | 
| 167 | 
            +
                #
         | 
| 168 | 
            +
                #     Dog.new.unproxied_save
         | 
| 169 | 
            +
                #     # => 'saved'
         | 
| 170 | 
            +
                #
         | 
| 171 | 
            +
                # And you can change the prefix for unproxied versions:
         | 
| 172 | 
            +
                #
         | 
| 173 | 
            +
                #     class Dog < Animal
         | 
| 174 | 
            +
                #       proxy_method :save, prefix: 'original_'
         | 
| 175 | 
            +
                #     end
         | 
| 176 | 
            +
                #
         | 
| 177 | 
            +
                #     Dog.new.original_save
         | 
| 178 | 
            +
                #     # => 'saved'
         | 
| 179 | 
            +
                #
         | 
| 180 | 
            +
                # Finally, you can actually *proxy* the method, by providing an
         | 
| 181 | 
            +
                # alternative block of code to run:
         | 
| 182 | 
            +
                #
         | 
| 183 | 
            +
                #     class Dog < Animal
         | 
| 184 | 
            +
                #       proxy_method(:save) do |object, method_name, *args, &block|
         | 
| 185 | 
            +
                #         "indirectly #{object.send(method_name)}"
         | 
| 186 | 
            +
                #       end
         | 
| 187 | 
            +
                #     end
         | 
| 188 | 
            +
                #
         | 
| 189 | 
            +
                #     Dog.new.save
         | 
| 190 | 
            +
                #     # => 'indirectly saved'
         | 
| 191 | 
            +
             | 
| 112 192 | 
             
                def proxy_instance_method(*original_method_names, &proxy_block)
         | 
| 113 193 | 
             
                  options = if original_method_names.last.is_a?(Hash)
         | 
| 114 194 | 
             
                    original_method_names.pop
         | 
    
        data/lib/proxy_method/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: proxy_method
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.2. | 
| 4 | 
            +
              version: 1.2.6
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jaime Bellmyer
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020-01- | 
| 11 | 
            +
            date: 2020-01-07 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: |2
         | 
| 14 14 | 
             
                  The purpose of this gem is to prevent directly running the inherited
         |