hook 0.0.1 → 0.0.2

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.
@@ -17,9 +17,21 @@ module Hook
17
17
  def around_#{method}(&block)
18
18
  around_hooks["#{method}"] << block
19
19
  end
20
+
21
+ def remove_#{method}_callbacks!
22
+ [before_hooks, after_hooks, around_hooks].each do |hooks|
23
+ hooks["#{method}"] = []
24
+ end
25
+ end
20
26
  HOOKS
21
27
  end
22
28
 
29
+ def remove_callbacks!
30
+ @before_hooks = nil
31
+ @after_hooks = nil
32
+ @around_hooks = nil
33
+ end
34
+
23
35
  def before_hooks
24
36
  @before_hooks ||= scoped_callbacks
25
37
  end
@@ -82,6 +82,28 @@ instance, here's what happens:
82
82
  after execute hooks run
83
83
  around execute hooks run
84
84
 
85
+ ### Resetting callbacks
86
+
87
+ The hook library allows you to remove configured callbacks for either a
88
+ specific hooked method, or for all hooked methods.
89
+
90
+ #### Specific Hooked Method
91
+ You can **remove all before, after, and around execute callbacks** on your class
92
+ with the "remove\_execute\_callbacks!" method:
93
+
94
+ ```ruby
95
+ Test.remove_execute_callbacks!
96
+ ```
97
+
98
+ #### All Hooked Methods
99
+
100
+ If you want to **remove all configured callbacks for all hooked methods** in
101
+ one fail swoop, you can use the "remove_callbacks" method:
102
+
103
+ ```ruby
104
+ Test.remove_callbacks!
105
+ ```
106
+
85
107
 
86
108
  ##LICENSE
87
109
 
@@ -45,3 +45,34 @@ a test executes:
45
45
  Test.new.execute
46
46
 
47
47
  around.should == "after"
48
+
49
+
50
+
51
+ remove all before, after, and around execute callbacks
52
+ ------------------------------------------------------
53
+
54
+ Test.around_hooks["execute"].should_not be_empty
55
+ Test.before_hooks["execute"].should_not be_empty
56
+ Test.after_hooks["execute"].should_not be_empty
57
+
58
+ Test.remove_execute_callbacks!
59
+
60
+ Test.around_hooks["execute"].should be_empty
61
+ Test.before_hooks["execute"].should be_empty
62
+ Test.after_hooks["execute"].should be_empty
63
+
64
+
65
+ remove all configured callbacks for all hooked methods
66
+ ------------------------------------------------------
67
+
68
+ Test.around_hooks["execute"].should_not be_empty
69
+ Test.before_hooks["execute"].should_not be_empty
70
+ Test.after_hooks["execute"].should_not be_empty
71
+
72
+ Test.remove_callbacks!
73
+
74
+ Test.around_hooks["execute"].should be_empty
75
+ Test.before_hooks["execute"].should be_empty
76
+ Test.after_hooks["execute"].should be_empty
77
+
78
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hook
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Parker
@@ -25,7 +25,7 @@ dependencies:
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: -726738688
28
+ hash: -2344376328
29
29
  segments:
30
30
  - 0
31
31
  - 4