ianwhite-hark 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +6 -0
- data/README.md +1 -1
- data/hark.gemspec +3 -4
- data/lib/hark/ad_hoc.rb +1 -0
- data/lib/hark/dispatcher.rb +3 -1
- data/lib/hark/listener.rb +9 -4
- data/lib/hark/version.rb +1 -1
- data/spec/hark_spec.rb +33 -26
- data/spec/spec_helper.rb +1 -1
- metadata +80 -74
- checksums.yaml +0 -7
- data/Guardfile +0 -9
data/.travis.yml
ADDED
data/README.md
CHANGED
data/hark.gemspec
CHANGED
@@ -9,17 +9,16 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Ian White"]
|
10
10
|
spec.email = ["ian.w.white@gmail.com"]
|
11
11
|
spec.description = %q{Create ad-hoc listener objects with impunity}
|
12
|
-
spec.summary = %q{Hark is a gem that enables writing code in a
|
12
|
+
spec.summary = %q{Hark is a gem that enables writing code in a "hexagonal architecture" or "tell don't ask" style}
|
13
13
|
spec.homepage = "http://github.com/ianwhite/hark"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "rspec
|
24
|
-
spec.add_development_dependency "guard-rspec"
|
23
|
+
spec.add_development_dependency "rspec"
|
25
24
|
end
|
data/lib/hark/ad_hoc.rb
CHANGED
data/lib/hark/dispatcher.rb
CHANGED
@@ -45,9 +45,11 @@ module Hark
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def handle method, *args, &block
|
48
|
-
|
48
|
+
results = []
|
49
|
+
handlers.each do |handler|
|
49
50
|
results << handler.send(method, *args, &block) if handler.respond_to?(method)
|
50
51
|
end
|
52
|
+
results
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
data/lib/hark/listener.rb
CHANGED
@@ -32,17 +32,22 @@ module Hark
|
|
32
32
|
end
|
33
33
|
|
34
34
|
class StrictListener < Listener
|
35
|
-
def
|
36
|
-
dispatcher.handles?(method)
|
35
|
+
def respond_to?(method, *args)
|
36
|
+
super || dispatcher.handles?(method)
|
37
37
|
end
|
38
38
|
|
39
39
|
def method_missing *args, &block
|
40
|
-
|
40
|
+
results = dispatcher.handle(*args, &block)
|
41
|
+
if results.length > 0
|
42
|
+
results
|
43
|
+
else
|
44
|
+
super
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
49
|
class LaxListener < Listener
|
45
|
-
def
|
50
|
+
def respond_to? *args
|
46
51
|
true
|
47
52
|
end
|
48
53
|
|
data/lib/hark/version.rb
CHANGED
data/spec/hark_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'hark'
|
3
3
|
|
4
4
|
describe Hark do
|
5
|
-
|
5
|
+
let(:transcript) { [] }
|
6
6
|
|
7
7
|
class PlainListener < Struct.new(:transcript)
|
8
8
|
def success(value)
|
@@ -16,54 +16,54 @@ describe Hark do
|
|
16
16
|
|
17
17
|
shared_examples_for "a success/failure listener" do
|
18
18
|
describe "success" do
|
19
|
-
|
20
|
-
|
19
|
+
before { listener.success(42) }
|
20
|
+
it { transcript.should == [[:succeeded, 42]] }
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "failure" do
|
24
|
-
|
25
|
-
|
24
|
+
before { listener.failure(54) }
|
25
|
+
it { transcript.should == [[:failed, 54]] }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
shared_examples_for "a strict listener" do
|
30
|
-
|
31
|
-
|
30
|
+
it { strict_listener.should_not respond_to(:unknown) }
|
31
|
+
it { expect{ strict_listener.unknown }.to raise_error(NoMethodError) }
|
32
32
|
end
|
33
33
|
|
34
34
|
shared_examples_for "a lax listener" do
|
35
|
-
|
36
|
-
|
35
|
+
it { lax_listener.should respond_to(:unknown) }
|
36
|
+
it { lax_listener.unknown.should == [] }
|
37
37
|
end
|
38
38
|
|
39
39
|
shared_examples_for "a success/failure hark listener" do
|
40
40
|
it_should_behave_like "a success/failure listener"
|
41
41
|
it_should_behave_like "a strict listener" do
|
42
|
-
|
42
|
+
let(:strict_listener) { listener }
|
43
43
|
end
|
44
44
|
|
45
45
|
context "when made lax" do
|
46
|
-
|
46
|
+
let(:lax_listener) { listener.lax }
|
47
47
|
it_should_behave_like "a lax listener"
|
48
48
|
|
49
49
|
context "and made strict again" do
|
50
|
-
|
50
|
+
let(:strict_listener) { lax_listener.strict }
|
51
51
|
it_should_behave_like "a strict listener"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
describe "A plain (non hark) listener object" do
|
57
|
-
|
57
|
+
let(:listener) { PlainListener.new(transcript) }
|
58
58
|
|
59
59
|
it_should_behave_like "a success/failure listener"
|
60
60
|
it_should_behave_like "a strict listener" do
|
61
|
-
|
61
|
+
let(:strict_listener) { listener }
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
describe "hark with respond_to style block" do
|
66
|
-
|
66
|
+
let(:listener) do
|
67
67
|
hark do |on|
|
68
68
|
on.success {|v| transcript.push [:succeeded, v] }
|
69
69
|
on.failure {|v| transcript.push [:failed, v] }
|
@@ -74,15 +74,15 @@ describe Hark do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
describe "hark with callables" do
|
77
|
-
|
78
|
-
hark success
|
77
|
+
let(:listener) do
|
78
|
+
hark :success => lambda{|v| transcript.push [:succeeded, v] }, :failure => lambda{|v| transcript.push [:failed, v] }
|
79
79
|
end
|
80
80
|
|
81
81
|
it_should_behave_like "a success/failure hark listener"
|
82
82
|
end
|
83
83
|
|
84
84
|
describe "hark built up in steps" do
|
85
|
-
|
85
|
+
let(:listener) do
|
86
86
|
l = hark
|
87
87
|
l = l.hark(:success) {|v| transcript.push [:succeeded, v] }
|
88
88
|
l = l.hark(:failure) {|v| transcript.push [:failed, v] }
|
@@ -92,24 +92,31 @@ describe Hark do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
describe "hark object" do
|
95
|
-
|
95
|
+
let(:listener) { hark PlainListener.new(transcript) }
|
96
96
|
|
97
97
|
it_should_behave_like "a success/failure hark listener"
|
98
98
|
end
|
99
99
|
|
100
100
|
describe "combine two listeners together" do
|
101
|
-
|
102
|
-
|
101
|
+
let(:logger) { hark(:signup_user) {|user| transcript << "User #{user} signed up" } }
|
102
|
+
let(:emailer) { hark(:signup_user) {|user| transcript << "Emailed #{user}" } }
|
103
103
|
|
104
|
-
|
104
|
+
let(:listener) { logger.hark(emailer) }
|
105
105
|
|
106
|
-
|
106
|
+
before { listener.signup_user("Fred") }
|
107
107
|
|
108
|
-
|
108
|
+
it { transcript.should == ["User Fred signed up", "Emailed Fred"] }
|
109
109
|
end
|
110
110
|
|
111
111
|
describe "lax/strict is preserved on #hark" do
|
112
|
-
|
113
|
-
|
112
|
+
it { hark.lax.hark.should be_a Hark::LaxListener }
|
113
|
+
it { hark.strict.hark.should be_a Hark::StrictListener }
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "when methods return falsy" do
|
117
|
+
let(:listener) { hark(:foo) { false } }
|
118
|
+
|
119
|
+
it { expect{ listener.foo }.to_not raise_error }
|
120
|
+
it { listener.foo.should == [false] }
|
114
121
|
end
|
115
122
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,81 +1,78 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ianwhite-hark
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
5
11
|
platform: ruby
|
6
|
-
authors:
|
12
|
+
authors:
|
7
13
|
- Ian White
|
8
14
|
autorequire:
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
17
|
+
|
18
|
+
date: 2013-11-14 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
14
21
|
name: bundler
|
15
|
-
|
16
|
-
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
17
25
|
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
|
20
|
-
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 9
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 3
|
31
|
+
version: "1.3"
|
21
32
|
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.3'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
33
|
type: :development
|
34
|
+
requirement: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rake
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
35
46
|
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec-given
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
47
|
type: :development
|
48
|
+
requirement: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
49
60
|
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: guard-rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
61
|
type: :development
|
63
|
-
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
62
|
+
requirement: *id003
|
69
63
|
description: Create ad-hoc listener objects with impunity
|
70
|
-
email:
|
64
|
+
email:
|
71
65
|
- ian.w.white@gmail.com
|
72
66
|
executables: []
|
67
|
+
|
73
68
|
extensions: []
|
69
|
+
|
74
70
|
extra_rdoc_files: []
|
75
|
-
|
71
|
+
|
72
|
+
files:
|
76
73
|
- .gitignore
|
74
|
+
- .travis.yml
|
77
75
|
- Gemfile
|
78
|
-
- Guardfile
|
79
76
|
- LICENSE.txt
|
80
77
|
- README.md
|
81
78
|
- Rakefile
|
@@ -89,29 +86,38 @@ files:
|
|
89
86
|
- spec/hark_spec.rb
|
90
87
|
- spec/spec_helper.rb
|
91
88
|
homepage: http://github.com/ianwhite/hark
|
92
|
-
licenses:
|
89
|
+
licenses:
|
93
90
|
- MIT
|
94
|
-
metadata: {}
|
95
91
|
post_install_message:
|
96
92
|
rdoc_options: []
|
97
|
-
|
93
|
+
|
94
|
+
require_paths:
|
98
95
|
- lib
|
99
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 3
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: "0"
|
109
114
|
requirements: []
|
115
|
+
|
110
116
|
rubyforge_project:
|
111
|
-
rubygems_version:
|
117
|
+
rubygems_version: 1.8.25
|
112
118
|
signing_key:
|
113
|
-
specification_version:
|
114
|
-
summary: Hark is a gem that enables writing code in a
|
115
|
-
test_files:
|
119
|
+
specification_version: 3
|
120
|
+
summary: Hark is a gem that enables writing code in a "hexagonal architecture" or "tell don't ask" style
|
121
|
+
test_files:
|
116
122
|
- spec/hark_spec.rb
|
117
123
|
- spec/spec_helper.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 257615d2c004b4af5d262c95bc085cc04a20113c
|
4
|
-
data.tar.gz: 6b53aeb761b46d56f932fe054866142f2e7b8657
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: c003deb6ef1d73e06cf9d06e17f06abc56d9ed99f6ca44b29eec664f51d4f0a9b3363c8d347e3dbac632419e8c891b1dcdb97d70af37285e8b6e7bb7b4109c6d
|
7
|
-
data.tar.gz: 0efa1f2ac66c433f8fb1b90d271dedfe135c995ef1300aa61c8fa63232731392460c308662d26b2db382cdbab5a478f6fced2ec7737f46721952301bc0ae3d78
|
data/Guardfile
DELETED