event_hooks 0.1.0 → 0.1.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.
- data/README.md +4 -4
- data/lib/event_hooks/event_hooks.rb +2 -0
- data/lib/event_hooks/version.rb +1 -1
- data/spec/event_hooks/event_hooks_spec.rb +21 -1
- data/spec/hook.sqlite3.db +0 -0
- metadata +1 -1
    
        data/README.md
    CHANGED
    
    | @@ -43,14 +43,14 @@ An example: | |
| 43 43 | 
             
            ```ruby
         | 
| 44 44 | 
             
            class AnyClass
         | 
| 45 45 | 
             
            	def submit
         | 
| 46 | 
            -
             | 
| 46 | 
            +
            		# do something
         | 
| 47 47 | 
             
            	end
         | 
| 48 48 | 
             
            	hook_before :submit, :submit_preconditions
         | 
| 49 49 | 
             
            	hook_after :submit, :submit_postconditions
         | 
| 50 50 |  | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 51 | 
            +
              	def submit_preconditions
         | 
| 52 | 
            +
            		am_i_ready?
         | 
| 53 | 
            +
              	end
         | 
| 54 54 |  | 
| 55 55 | 
             
            	def submit_postconditions
         | 
| 56 56 | 
             
            		am_i_ready?
         | 
| @@ -29,6 +29,8 @@ module EventHooks | |
| 29 29 | 
             
            		end
         | 
| 30 30 |  | 
| 31 31 | 
             
            		def hook_after(event, hook)
         | 
| 32 | 
            +
            			raise EventHooks::DoubleHook.new if instance_methods.include?("#{event}_without_after_hook".to_sym)
         | 
| 33 | 
            +
             | 
| 32 34 | 
             
            			alias_method "#{event}_without_after_hook".to_sym, event
         | 
| 33 35 |  | 
| 34 36 | 
             
            			define_method "#{event}_with_after_hook".to_sym do |*args|
         | 
    
        data/lib/event_hooks/version.rb
    CHANGED
    
    
| @@ -56,7 +56,11 @@ describe "any class" do | |
| 56 56 | 
             
            			end
         | 
| 57 57 | 
             
            		end
         | 
| 58 58 |  | 
| 59 | 
            -
            		context "when you  | 
| 59 | 
            +
            		context "when you add the same hook to another event" do
         | 
| 60 | 
            +
            			it "works" 
         | 
| 61 | 
            +
            		end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            		context "when you try to add another before hook to the same event" do
         | 
| 60 64 | 
             
            			class StateMachine
         | 
| 61 65 | 
             
            				def another_hook
         | 
| 62 66 | 
             
            				end
         | 
| @@ -136,5 +140,21 @@ describe "any ActiveRecord::Base subclass" do | |
| 136 140 | 
             
            				end
         | 
| 137 141 | 
             
            			end
         | 
| 138 142 | 
             
            		end
         | 
| 143 | 
            +
             | 
| 144 | 
            +
            		context "when you try to add the same hook to another event" do
         | 
| 145 | 
            +
            			it "works"
         | 
| 146 | 
            +
            		end
         | 
| 147 | 
            +
             | 
| 148 | 
            +
            		context "when you try to add another after hook to the same event" do
         | 
| 149 | 
            +
            			class Foo
         | 
| 150 | 
            +
            				def another_hook
         | 
| 151 | 
            +
            				end
         | 
| 152 | 
            +
            			end
         | 
| 153 | 
            +
             | 
| 154 | 
            +
            			it "raises a DoubleHook exception" do
         | 
| 155 | 
            +
            				expect { Foo.send :hook_after, :submit, :another_hook }.
         | 
| 156 | 
            +
            						to raise_exception(EventHooks::DoubleHook)
         | 
| 157 | 
            +
            			end
         | 
| 158 | 
            +
            		end
         | 
| 139 159 | 
             
            	end
         | 
| 140 160 | 
             
            end
         | 
    
        data/spec/hook.sqlite3.db
    CHANGED
    
    | Binary file |