heed 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +4 -0
- data/README.md +5 -5
- data/lib/hark/core_ext.rb +2 -2
- data/lib/hark/version.rb +1 -1
- data/spec/hark_spec.rb +3 -3
- 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: 9aa08585301fcc08e8968c5773f0e7c4ecadc65d
|
4
|
+
data.tar.gz: 3f0cea242cd9ac55909ed9b67c6bb2be83c82a2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2a21bc055d7676ea2c7a658ce6d58e2c5d77830653e47338a794d4046f68483dcd7116bb209bffe886fb51d471a0235bee393aeeab2420ab83f68f74025071b
|
7
|
+
data.tar.gz: d6aaf0eff296699a569f32536a8c3dcf490689519f78d926cad5ba217a803dac3f2adf34fa7ef38a3a96aef7fc2a605890ff32f50bfba5a43d5db95bf0843a03
|
data/History.md
CHANGED
data/README.md
CHANGED
@@ -30,7 +30,7 @@ started with a tell-dont-ask style, in rails controllers for example. For more
|
|
30
30
|
|
31
31
|
## Usage
|
32
32
|
|
33
|
-
###
|
33
|
+
### `hark`: create a listener
|
34
34
|
|
35
35
|
To create a listener object use `hark`.
|
36
36
|
|
@@ -107,7 +107,7 @@ Turn any object into a listener, adding new methods as we go
|
|
107
107
|
|
108
108
|
Now, when listener is sent #created, all create handlers are called.
|
109
109
|
|
110
|
-
###
|
110
|
+
### `heed` call a message with an ad-hoc listener
|
111
111
|
|
112
112
|
Because of the precedence of the block operator, constructing ad-hoc listeners requires
|
113
113
|
you to insert some parens, which might be seen as unsightly, e.g:
|
@@ -117,9 +117,9 @@ you to insert some parens, which might be seen as unsightly, e.g:
|
|
117
117
|
on.invalid_item {|item| redirect_to item, error: "Item not evaluable" }
|
118
118
|
end))
|
119
119
|
|
120
|
-
You may use
|
120
|
+
You may use #heed to create an ad-hoc listener using a passed block as follows
|
121
121
|
|
122
|
-
seller
|
122
|
+
heed seller, :request_valuation, item do |on|
|
123
123
|
on.valuation_requested {|valuation| redirect_to valuation}
|
124
124
|
on.invalid_item {|item| redirect_to item, error: "Item not evaluable" }
|
125
125
|
end
|
@@ -127,7 +127,7 @@ You may use Kernerl#hearken to create an ad-hoc listener using a passed block as
|
|
127
127
|
If you want to combine listeners with an ad-hoc block, you may pass a 0-arity block that is
|
128
128
|
yielded as the listener
|
129
129
|
|
130
|
-
seller
|
130
|
+
heed seller, :request_valuation, item do
|
131
131
|
hark valuation_notifier do |on|
|
132
132
|
on.valuation_requested {|valuation| redirect_to valuation}
|
133
133
|
on.invalid_item {|item| redirect_to item, error: "Item not evaluable" }
|
data/lib/hark/core_ext.rb
CHANGED
data/lib/hark/version.rb
CHANGED
data/spec/hark_spec.rb
CHANGED
@@ -136,7 +136,7 @@ describe Hark do
|
|
136
136
|
it { listener.foo.should == [false] }
|
137
137
|
end
|
138
138
|
|
139
|
-
describe "#
|
139
|
+
describe "Kernel#heed object, :method" do
|
140
140
|
let(:object) do
|
141
141
|
Object.new.tap do |obj|
|
142
142
|
class << obj
|
@@ -150,7 +150,7 @@ describe Hark do
|
|
150
150
|
|
151
151
|
context "with 1 arity block" do
|
152
152
|
it "sends :method with an ad-hoc listener created from the block" do
|
153
|
-
object
|
153
|
+
heed object, :foo, "ONE", "TWO" do |on|
|
154
154
|
on.foo {|a| transcript << [:foo, a] }
|
155
155
|
on.bar {|a| transcript << [:bar, a] }
|
156
156
|
end
|
@@ -162,7 +162,7 @@ describe Hark do
|
|
162
162
|
it "sends :method with listener created by yielding to the block" do
|
163
163
|
foo = hark(:foo) {|a| transcript << [:foo, a] }
|
164
164
|
|
165
|
-
object
|
165
|
+
heed object, :foo, "ONE", "TWO" do
|
166
166
|
hark(foo, :bar) {|a| transcript << [:bar, a] }
|
167
167
|
end
|
168
168
|
transcript.should == [[:foo, "ONE"], [:bar, "TWO"]]
|