event_hooks 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.
- data/README.md +24 -2
- data/lib/event_hooks/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# EventHooks
|
2
2
|
|
3
|
-
|
3
|
+
EventHooks enhances Ruby classes to allow adding pre-conditions to method calls (events).
|
4
|
+
If the pre-conditions method returns false the event method will not run. It can be used on ActiveRecord subclasses to validate some conditions only when a certain event occurs.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -18,7 +19,28 @@ Or install it yourself as:
|
|
18
19
|
|
19
20
|
## Usage
|
20
21
|
|
21
|
-
|
22
|
+
Within the class that you want to hook the pre-condition to simply write:
|
23
|
+
```ruby
|
24
|
+
hook_before :event, :hook
|
25
|
+
```
|
26
|
+
|
27
|
+
where:
|
28
|
+
* event is the name of a method that you must define prior to the hook_before.
|
29
|
+
* hook is the name of a method that will be run before the call to event.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class AnyClass
|
33
|
+
def submit
|
34
|
+
# do something
|
35
|
+
end
|
36
|
+
hook_before :submit, :submit_preconditions
|
37
|
+
|
38
|
+
def submit_preconditions
|
39
|
+
am_i_ready?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
22
44
|
|
23
45
|
## Contributing
|
24
46
|
|
data/lib/event_hooks/version.rb
CHANGED