spine-hub 0.1.0 → 0.5.0
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/CHANGELOG.md +10 -0
- data/Gemfile.lock +27 -14
- data/README.md +28 -1
- data/lib/spine/hub.rb +4 -0
- data/lib/spine/hub/publisher.rb +1 -23
- data/lib/spine/hub/subscriptions/global.rb +11 -0
- data/lib/spine/hub/subscriptions/registry.rb +38 -0
- data/lib/spine/hub/version.rb +1 -1
- data/spec/config/coverage.rb +4 -0
- data/spec/spine/hub/hub_spec.rb +41 -0
- data/spec/spine/hub/publisher_spec.rb +1 -1
- data/spine-hub.gemspec +3 -3
- metadata +28 -8
- data/lib/spine-hub.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59850424d260a03882539d770413de4f30601b98
|
4
|
+
data.tar.gz: 2454e087becb882f020190141cc422b2ffbc4c6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7f05363dcbc4fe4293cb0d0d89e98295dab58ad8effe576c891f19c481dead58944cccb4bd07a4036e4276a82a68bc6c6d57db4685f9f23869197671e2e883b
|
7
|
+
data.tar.gz: 893ffbc92a336d8aa804a1a3b03e688d885f1cd5c7d84c2e6f77d2a136eee5f74c21e14b5bde4590f08ee7ed8388a1d1124002ef0a702426e8ebebaa0032dcbf
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
@@ -1,32 +1,45 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
spine-hub (0.
|
4
|
+
spine-hub (0.5.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
codeclimate-test-reporter (0.4.7)
|
10
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
9
11
|
diff-lcs (1.2.5)
|
12
|
+
docile (1.1.5)
|
13
|
+
json (1.8.3)
|
10
14
|
rake (10.4.2)
|
11
|
-
rspec (3.
|
12
|
-
rspec-core (~> 3.
|
13
|
-
rspec-expectations (~> 3.
|
14
|
-
rspec-mocks (~> 3.
|
15
|
-
rspec-core (3.
|
16
|
-
rspec-support (~> 3.
|
17
|
-
rspec-expectations (3.
|
15
|
+
rspec (3.3.0)
|
16
|
+
rspec-core (~> 3.3.0)
|
17
|
+
rspec-expectations (~> 3.3.0)
|
18
|
+
rspec-mocks (~> 3.3.0)
|
19
|
+
rspec-core (3.3.0)
|
20
|
+
rspec-support (~> 3.3.0)
|
21
|
+
rspec-expectations (3.3.0)
|
18
22
|
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.
|
20
|
-
rspec-mocks (3.
|
23
|
+
rspec-support (~> 3.3.0)
|
24
|
+
rspec-mocks (3.3.0)
|
21
25
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-support (3.
|
26
|
+
rspec-support (~> 3.3.0)
|
27
|
+
rspec-support (3.3.0)
|
28
|
+
simplecov (0.10.0)
|
29
|
+
docile (~> 1.1.0)
|
30
|
+
json (~> 1.8)
|
31
|
+
simplecov-html (~> 0.10.0)
|
32
|
+
simplecov-html (0.10.0)
|
24
33
|
|
25
34
|
PLATFORMS
|
26
35
|
ruby
|
27
36
|
|
28
37
|
DEPENDENCIES
|
29
|
-
bundler (~> 1.
|
38
|
+
bundler (~> 1.10)
|
39
|
+
codeclimate-test-reporter (~> 0.4)
|
30
40
|
rake (~> 10.0)
|
31
|
-
rspec (~> 3
|
41
|
+
rspec (~> 3)
|
32
42
|
spine-hub!
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
1.10.6
|
data/README.md
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/spine-hub)
|
4
4
|
[](https://gemnasium.com/rspine/hub)
|
5
|
+
[](https://codeclimate.com/github/rspine/hub/coverage)
|
5
6
|
[](https://codeclimate.com/github/rspine/hub)
|
7
|
+
[](https://hakiri.io/github/rspine/hub/master)
|
8
|
+
[](http://inch-ci.org/github/rspine/hub)
|
6
9
|
[](https://codeship.com/projects/81031)
|
7
10
|
|
8
11
|
Provides Publish/Subscribe pattern.
|
@@ -39,7 +42,7 @@ class Listener
|
|
39
42
|
end
|
40
43
|
|
41
44
|
service = Service.new
|
42
|
-
service.subscribe(Listener)
|
45
|
+
service.subscribe(Listener.new)
|
43
46
|
service.on(:action_executed) do |status|
|
44
47
|
puts "Action executed: #{ status }"
|
45
48
|
end
|
@@ -57,3 +60,27 @@ class MySubscriber
|
|
57
60
|
end
|
58
61
|
end
|
59
62
|
```
|
63
|
+
|
64
|
+
When global subscribers are needed, extend your publisher with
|
65
|
+
`Spine::Hub::Subcriptions::Global` module. It also works with `Repeater`
|
66
|
+
module.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
class Service
|
70
|
+
include Spine::Hub::Publisher
|
71
|
+
include Spine::Hub::Subscriptions::Global
|
72
|
+
|
73
|
+
def action
|
74
|
+
# ...
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
For registering to global scope:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
Spine::Hub.subscribe(MySubscriber.new)
|
83
|
+
Spine::Hub.on(:my_event) do |argument|
|
84
|
+
# ...
|
85
|
+
end
|
86
|
+
```
|
data/lib/spine/hub.rb
CHANGED
@@ -6,6 +6,10 @@ module Spine
|
|
6
6
|
|
7
7
|
module Subscriptions
|
8
8
|
autoload :Closure, 'spine/hub/subscriptions/closure'
|
9
|
+
autoload :Registry, 'spine/hub/subscriptions/registry'
|
10
|
+
autoload :Global, 'spine/hub/subscriptions/global'
|
9
11
|
end
|
12
|
+
|
13
|
+
extend Subscriptions::Registry
|
10
14
|
end
|
11
15
|
end
|
data/lib/spine/hub/publisher.rb
CHANGED
@@ -1,18 +1,7 @@
|
|
1
1
|
module Spine
|
2
2
|
module Hub
|
3
3
|
module Publisher
|
4
|
-
|
5
|
-
@subscribers ||= []
|
6
|
-
end
|
7
|
-
|
8
|
-
# Adds subscribers.
|
9
|
-
#
|
10
|
-
# ==== Attributes
|
11
|
-
# * +subscribers+ - List of addable subscribers.
|
12
|
-
def subscribe(*subscribers)
|
13
|
-
@subscribers ||= []
|
14
|
-
@subscribers += subscribers
|
15
|
-
end
|
4
|
+
include Subscriptions::Registry
|
16
5
|
|
17
6
|
# Publishes event to subscribers.
|
18
7
|
#
|
@@ -26,17 +15,6 @@ module Spine
|
|
26
15
|
end
|
27
16
|
end
|
28
17
|
end
|
29
|
-
|
30
|
-
# Adds block subscriber.
|
31
|
-
#
|
32
|
-
# ==== Arguments
|
33
|
-
# * +event+ - Subscriber triggering event.
|
34
|
-
def on(event, &block)
|
35
|
-
if block_given?
|
36
|
-
subscribe(Subscriptions::Closure.new(event, block))
|
37
|
-
end
|
38
|
-
self
|
39
|
-
end
|
40
18
|
end
|
41
19
|
end
|
42
20
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module Spine
|
4
|
+
module Hub
|
5
|
+
module Subscriptions
|
6
|
+
module Registry
|
7
|
+
def subscribers
|
8
|
+
@subscribers ||= Set.new
|
9
|
+
end
|
10
|
+
|
11
|
+
# Removes all subscribers.
|
12
|
+
def unsubscribe_all
|
13
|
+
@subscribers = Set.new
|
14
|
+
end
|
15
|
+
|
16
|
+
# Adds subscribers.
|
17
|
+
#
|
18
|
+
# ==== Attributes
|
19
|
+
# * +subscribers+ - List of addable subscribers.
|
20
|
+
def subscribe(*subscribers)
|
21
|
+
@subscribers ||= Set.new
|
22
|
+
@subscribers += subscribers
|
23
|
+
end
|
24
|
+
|
25
|
+
# Adds block subscriber.
|
26
|
+
#
|
27
|
+
# ==== Arguments
|
28
|
+
# * +event+ - Subscriber triggering event.
|
29
|
+
def on(event, &block)
|
30
|
+
if block_given?
|
31
|
+
subscribe(Subscriptions::Closure.new(event, block))
|
32
|
+
end
|
33
|
+
self
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/spine/hub/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spine/hub'
|
2
|
+
|
3
|
+
module Spine
|
4
|
+
module Hub
|
5
|
+
describe Hub do
|
6
|
+
subject { Hub }
|
7
|
+
before(:each) { subject.unsubscribe_all }
|
8
|
+
after(:each) { subject.unsubscribe_all }
|
9
|
+
|
10
|
+
let(:subscriber) { double }
|
11
|
+
let(:publisher) {
|
12
|
+
double.extend(Publisher).extend(Subscriptions::Global)
|
13
|
+
}
|
14
|
+
let(:local_publisher) { double.extend(Publisher) }
|
15
|
+
|
16
|
+
it 'adds global subscribers' do
|
17
|
+
subject.subscribe(subscriber)
|
18
|
+
expect(subject.subscribers.count).to eq(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'notifies global subscribers' do
|
22
|
+
expect(subscriber).to receive(:notify).with(:test, 1)
|
23
|
+
|
24
|
+
subject.subscribe(subscriber)
|
25
|
+
publisher.publish(:test, 1)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'clears subscribers' do
|
29
|
+
subject.subscribe(double)
|
30
|
+
subject.subscribe(double)
|
31
|
+
subject.unsubscribe_all
|
32
|
+
expect(subject.subscribers.count).to eq(0)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'ignores global subcribers on local publisher' do
|
36
|
+
subject.subscribe(double)
|
37
|
+
expect(local_publisher.subscribers.size).to eq(0)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spine-hub.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'spine/hub/version'
|
@@ -18,7 +17,8 @@ Gem::Specification.new do |spec|
|
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
21
|
-
spec.add_development_dependency 'bundler', "~> 1.
|
20
|
+
spec.add_development_dependency 'bundler', "~> 1.10"
|
22
21
|
spec.add_development_dependency 'rake', "~> 10.0"
|
23
|
-
spec.add_development_dependency 'rspec', "~> 3
|
22
|
+
spec.add_development_dependency 'rspec', "~> 3"
|
23
|
+
spec.add_development_dependency 'codeclimate-test-reporter', "~> 0.4"
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spine-hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TOGGL LLC
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.10'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3
|
47
|
+
version: '3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3
|
54
|
+
version: '3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
55
69
|
description: ''
|
56
70
|
email:
|
57
71
|
- support@toggl.com
|
@@ -61,19 +75,23 @@ extra_rdoc_files: []
|
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
63
77
|
- ".rspec"
|
78
|
+
- CHANGELOG.md
|
64
79
|
- Gemfile
|
65
80
|
- Gemfile.lock
|
66
81
|
- LICENSE
|
67
82
|
- README.md
|
68
83
|
- Rakefile
|
69
|
-
- lib/spine-hub.rb
|
70
84
|
- lib/spine/hub.rb
|
71
85
|
- lib/spine/hub/publisher.rb
|
72
86
|
- lib/spine/hub/repeater.rb
|
73
87
|
- lib/spine/hub/subscriber.rb
|
74
88
|
- lib/spine/hub/subscriptions/closure.rb
|
89
|
+
- lib/spine/hub/subscriptions/global.rb
|
90
|
+
- lib/spine/hub/subscriptions/registry.rb
|
75
91
|
- lib/spine/hub/version.rb
|
92
|
+
- spec/config/coverage.rb
|
76
93
|
- spec/config/default.rb
|
94
|
+
- spec/spine/hub/hub_spec.rb
|
77
95
|
- spec/spine/hub/publisher_spec.rb
|
78
96
|
- spec/spine/hub/subscriber_spec.rb
|
79
97
|
- spine-hub.gemspec
|
@@ -97,11 +115,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
115
|
version: '0'
|
98
116
|
requirements: []
|
99
117
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.4.5
|
118
|
+
rubygems_version: 2.4.5.1
|
101
119
|
signing_key:
|
102
120
|
specification_version: 4
|
103
121
|
summary: Spine hub for Ruby applications.
|
104
122
|
test_files:
|
123
|
+
- spec/config/coverage.rb
|
105
124
|
- spec/config/default.rb
|
125
|
+
- spec/spine/hub/hub_spec.rb
|
106
126
|
- spec/spine/hub/publisher_spec.rb
|
107
127
|
- spec/spine/hub/subscriber_spec.rb
|
data/lib/spine-hub.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'spine/hub'
|