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 CHANGED
@@ -43,14 +43,14 @@ An example:
43
43
  ```ruby
44
44
  class AnyClass
45
45
  def submit
46
- # do something
46
+ # do something
47
47
  end
48
48
  hook_before :submit, :submit_preconditions
49
49
  hook_after :submit, :submit_postconditions
50
50
 
51
- def submit_preconditions
52
- am_i_ready?
53
- end
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|
@@ -1,3 +1,3 @@
1
1
  module EventHooks
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -56,7 +56,11 @@ describe "any class" do
56
56
  end
57
57
  end
58
58
 
59
- context "when you try to add another before hook" do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: