ianwhite-hark 0.0.5 → 0.0.6
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 +4 -4
- data/History.md +4 -0
- data/README.md +10 -4
- data/lib/hark/core_ext.rb +0 -4
- data/lib/hark/version.rb +1 -1
- data/spec/hark_spec.rb +0 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c1768749a71703d7f3a754773c0dda1b9b9c754
|
4
|
+
data.tar.gz: c704b92cd229dc37ecb44a0fa5daff446b64b313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3da05565f8c13dc4d477441f48be5cb746797f6e854af8152c09326b564cd2e6010e177ddaf5c2832472430fec6d7825f2e21665c096ac8854bece6cf22adb4e
|
7
|
+
data.tar.gz: 397d7d99fe5936cca9661fc7e0eb00ef8bbcf484f74f3b04c4e029cf7fcd880dbe2efc6a5f938b0bdc63f8070c869a0bbb5ca9bc2cbdff5e4828925260c95b22
|
data/History.md
CHANGED
data/README.md
CHANGED
@@ -42,7 +42,7 @@ You can pass a symbol and block
|
|
42
42
|
|
43
43
|
The following methods are more suitable for a listener with multiple messages.
|
44
44
|
|
45
|
-
A hash with callables as
|
45
|
+
A hash with callables as values
|
46
46
|
|
47
47
|
hark(
|
48
48
|
created: ->(user) { redirect_to(user, notice: "You have signed up!") },
|
@@ -50,7 +50,7 @@ A hash with callables as keys
|
|
50
50
|
)
|
51
51
|
|
52
52
|
# assuming some methods for rendering and redirecting exist on the controller
|
53
|
-
|
53
|
+
hark(created: method(:redirect_to_user), invalid: method(:render_new))
|
54
54
|
|
55
55
|
Or, a 'respond_to' style block
|
56
56
|
|
@@ -99,9 +99,15 @@ Combine with any object that support the same protocol
|
|
99
99
|
logger = UserLogger.new # responds to :created
|
100
100
|
listener = listener.hark(logger)
|
101
101
|
|
102
|
+
Turn any object into a listener, adding new methods as we go
|
103
|
+
|
104
|
+
hark UserLogger.new do |on|
|
105
|
+
on.created {|user| Emailer.send_welcom_email(user) }
|
106
|
+
end
|
107
|
+
|
102
108
|
Now, when listener is sent #created, all create handlers are called.
|
103
109
|
|
104
|
-
### Sugar: #hearken
|
110
|
+
### Sugar: `Kernel#hearken`
|
105
111
|
|
106
112
|
Because of the precedence of the block operator, constructing ad-hoc listeners requires
|
107
113
|
you to insert some parens, which might be seen as unsightly, e.g:
|
@@ -118,7 +124,7 @@ You may use Kernerl#hearken to create an ad-hoc listener using a passed block as
|
|
118
124
|
on.invalid_item {|item| redirect_to item, error: "Item not evaluable" }
|
119
125
|
end
|
120
126
|
|
121
|
-
If you want to combine listeners with an ad-hoc
|
127
|
+
If you want to combine listeners with an ad-hoc block, you may pass a 0-arity block that is
|
122
128
|
yielded as the listener
|
123
129
|
|
124
130
|
seller.hearken :request_valuation, item do
|
data/lib/hark/core_ext.rb
CHANGED
data/lib/hark/version.rb
CHANGED
data/spec/hark_spec.rb
CHANGED
@@ -97,12 +97,6 @@ describe Hark do
|
|
97
97
|
it_should_behave_like "a success/failure hark listener"
|
98
98
|
end
|
99
99
|
|
100
|
-
describe "object.to_hark" do
|
101
|
-
let(:listener) { PlainListener.new(transcript).to_hark }
|
102
|
-
|
103
|
-
it_should_behave_like "a success/failure hark listener"
|
104
|
-
end
|
105
|
-
|
106
100
|
describe "combine two listeners together" do
|
107
101
|
let(:logger) { hark(:signup_user) {|user| transcript << "User #{user} signed up" } }
|
108
102
|
let(:emailer) { hark(:signup_user) {|user| transcript << "Emailed #{user}" } }
|