pre-action 0.1
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 +7 -0
- data/lib/pre_action.rb +34 -0
- metadata +43 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 4d60d586d2a9aec4a4c911aaee3562ca59bbd7ee
         | 
| 4 | 
            +
              data.tar.gz: 32d8ab617228802a9640fcd2ecb7ef7ad628ab9c
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 1d3d693b92d9d7c5117c6c5f01d498a5cc73d664bf8576fbf18d6bcaf77b218e026c304ff4884fe433e1c7f42ddcaebb7d40951160e45a715f43af74e2447426
         | 
| 7 | 
            +
              data.tar.gz: e2396633408d619a539a242e55492735b76e3a6530b3ffbe1ff8eeeaee626e963ba9c59b53c0a29ddf0ef98e4026d764b567d8163aec5309cac46c397a7769c1
         | 
    
        data/lib/pre_action.rb
    ADDED
    
    | @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            module PreAction
         | 
| 2 | 
            +
            	def self.included base
         | 
| 3 | 
            +
            		base.extend(Methods)
         | 
| 4 | 
            +
            	end
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            	module Methods
         | 
| 7 | 
            +
            		def pre_action pre_action_name, action_names
         | 
| 8 | 
            +
            			raise 'no actions for running pre-action' unless action_names.has_key?(:for)
         | 
| 9 | 
            +
            			@actions = action_names[:for]
         | 
| 10 | 
            +
            			@pre_action = pre_action_name
         | 
| 11 | 
            +
            			@updated_action = {}
         | 
| 12 | 
            +
            			@actions.each{|a| @updated_action[a] = false}
         | 
| 13 | 
            +
            		end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            		def method_added method
         | 
| 16 | 
            +
            			return unless @actions
         | 
| 17 | 
            +
            			return if @actions.empty?
         | 
| 18 | 
            +
            			return unless @actions.include? method
         | 
| 19 | 
            +
            			return if @updated_action[method]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            			method_impl = instance_method(method)
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            			method_fork = %Q{
         | 
| 24 | 
            +
            				define_method :#{method.to_s} do
         | 
| 25 | 
            +
            					self.#{@pre_action}
         | 
| 26 | 
            +
            					method_impl.bind(self).call
         | 
| 27 | 
            +
            				end
         | 
| 28 | 
            +
            			}
         | 
| 29 | 
            +
            			@updated_action[method] = true
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            			self.class_eval(method_fork)
         | 
| 32 | 
            +
            		end
         | 
| 33 | 
            +
            	end
         | 
| 34 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,43 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: pre-action
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: '0.1'
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Fevin Fu
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2013-06-08 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies: []
         | 
| 13 | 
            +
            description: 
         | 
| 14 | 
            +
            email: fevin86@gmail.com
         | 
| 15 | 
            +
            executables: []
         | 
| 16 | 
            +
            extensions: []
         | 
| 17 | 
            +
            extra_rdoc_files: []
         | 
| 18 | 
            +
            files:
         | 
| 19 | 
            +
            - lib/pre_action.rb
         | 
| 20 | 
            +
            homepage: 
         | 
| 21 | 
            +
            licenses: []
         | 
| 22 | 
            +
            metadata: {}
         | 
| 23 | 
            +
            post_install_message: 
         | 
| 24 | 
            +
            rdoc_options: []
         | 
| 25 | 
            +
            require_paths:
         | 
| 26 | 
            +
            - lib
         | 
| 27 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 28 | 
            +
              requirements:
         | 
| 29 | 
            +
              - - '>='
         | 
| 30 | 
            +
                - !ruby/object:Gem::Version
         | 
| 31 | 
            +
                  version: '0'
         | 
| 32 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 33 | 
            +
              requirements:
         | 
| 34 | 
            +
              - - '>='
         | 
| 35 | 
            +
                - !ruby/object:Gem::Version
         | 
| 36 | 
            +
                  version: '0'
         | 
| 37 | 
            +
            requirements: []
         | 
| 38 | 
            +
            rubyforge_project: 
         | 
| 39 | 
            +
            rubygems_version: 2.0.3
         | 
| 40 | 
            +
            signing_key: 
         | 
| 41 | 
            +
            specification_version: 4
         | 
| 42 | 
            +
            summary: a simple aop just for adding pre action before selected methods in class
         | 
| 43 | 
            +
            test_files: []
         |