ianwhite-hark 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -18
- data/lib/hark/core_ext.rb +0 -4
- data/lib/hark/version.rb +1 -1
- data/spec/hark_spec.rb +2 -2
- 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: 257615d2c004b4af5d262c95bc085cc04a20113c
|
4
|
+
data.tar.gz: 6b53aeb761b46d56f932fe054866142f2e7b8657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c003deb6ef1d73e06cf9d06e17f06abc56d9ed99f6ca44b29eec664f51d4f0a9b3363c8d347e3dbac632419e8c891b1dcdb97d70af37285e8b6e7bb7b4109c6d
|
7
|
+
data.tar.gz: 0efa1f2ac66c433f8fb1b90d271dedfe135c995ef1300aa61c8fa63232731392460c308662d26b2db382cdbab5a478f6fced2ec7737f46721952301bc0ae3d78
|
data/README.md
CHANGED
@@ -1,13 +1,31 @@
|
|
1
|
-
# Hark
|
1
|
+
# Hark [![Code Climate](https://codeclimate.com/repos/52691919c7f3a37a2301dfc5/badges/8f5a4caa333ec7a654ec/gpa.png)](https://codeclimate.com/repos/52691919c7f3a37a2301dfc5/feed) [![Build Status](https://travis-ci.org/ianwhite/hark.png)](https://travis-ci.org/ianwhite/hark)
|
2
2
|
|
3
3
|
Create an ad-hoc listener object with hark.
|
4
4
|
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ianwhite-hark'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ianwhite-hark
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
5
21
|
The idea behind hark is that the objects that receive listeners shouldn't need to perform any ceremony on
|
6
22
|
them, just treat them as objects that respond to messages. It's up to the caller to provide these lsitener objects,
|
7
|
-
and to decide how they behave
|
23
|
+
and to decide how they behave, perhaps combining together listeners (in an subscriber fashion). If required, these ad-hoc
|
8
24
|
listeners can easily be refactored into classes in their own right, as the recievers don't need to know anything about
|
9
25
|
hark.
|
10
26
|
|
27
|
+
Tell don't ask style is encouraged with hark. That said, the return value for a message sent to a hark listener is an array of all of the return values.
|
28
|
+
|
11
29
|
listener = hark success: ->{ "succeeded" }, failure: ->{ "failed" }
|
12
30
|
listener.success # => ["succeeded"]
|
13
31
|
listener.failure # => ["failed"]
|
@@ -38,27 +56,23 @@ To add new messages to a listener, use #hark
|
|
38
56
|
|
39
57
|
To decorate an object (of any sort) so that it becomes a hark listener (and therefore can be smushed etc)
|
40
58
|
|
41
|
-
listener = object
|
59
|
+
listener = hark(object)
|
42
60
|
|
43
61
|
The listener is immutable, #strict, #lax, and #hark all return new listeners
|
44
62
|
|
45
|
-
|
46
|
-
|
47
|
-
Add this line to your application's Gemfile:
|
48
|
-
|
49
|
-
gem 'ianwhite-hark'
|
50
|
-
|
51
|
-
And then execute:
|
63
|
+
Here's an example from a rails controller
|
52
64
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
$ gem install ianwhite-hark
|
58
|
-
|
59
|
-
## Usage
|
65
|
+
def create
|
66
|
+
SignupNewUser.new params, hark(create_response, SignupEmailer.new)
|
67
|
+
end
|
60
68
|
|
61
|
-
|
69
|
+
# response block style
|
70
|
+
def create_response
|
71
|
+
hark do |on|
|
72
|
+
on.signed_up {|user| redirect_to user, notice: "Signed up!" }
|
73
|
+
on.invalid {|user| render "new", user: user }
|
74
|
+
end
|
75
|
+
end
|
62
76
|
|
63
77
|
## Contributing
|
64
78
|
|
data/lib/hark/core_ext.rb
CHANGED
data/lib/hark/version.rb
CHANGED
data/spec/hark_spec.rb
CHANGED
@@ -91,8 +91,8 @@ describe Hark do
|
|
91
91
|
it_should_behave_like "a success/failure hark listener"
|
92
92
|
end
|
93
93
|
|
94
|
-
describe "object
|
95
|
-
Given(:listener) { PlainListener.new(transcript)
|
94
|
+
describe "hark object" do
|
95
|
+
Given(:listener) { hark PlainListener.new(transcript) }
|
96
96
|
|
97
97
|
it_should_behave_like "a success/failure hark listener"
|
98
98
|
end
|