informator 0.0.2 → 0.1.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/.travis.yml +2 -1
- data/CHANGELOG.md +12 -0
- data/Gemfile +3 -1
- data/Guardfile +1 -1
- data/README.md +4 -4
- data/Rakefile +9 -7
- data/informator.gemspec +3 -2
- data/lib/informator.rb +4 -3
- data/lib/informator/event.rb +15 -14
- data/lib/informator/reporter.rb +4 -4
- data/lib/informator/subscriber.rb +3 -3
- data/lib/informator/version.rb +1 -1
- data/spec/unit/informator/event_spec.rb +5 -5
- data/spec/unit/informator/subscriber_spec.rb +3 -3
- data/spec/{integration → unit}/informator_spec.rb +9 -3
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53d7f784fa22bf7f691c99d5e59f054c0c0ba3fb
|
4
|
+
data.tar.gz: 37dcc4751f1433fdcfdc9fc5650f6776ec065100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e22da1a142f55e6535b54db59652546cd750d23cfc237329eb7d3a11cb21b2ce6cfaffaab64563f941c91f0336f4f2af197a6bdf6702baf951646a2a7586b34d
|
7
|
+
data.tar.gz: 5463ec47db2b542e465f0bbc546068ee9a48dc9aca6e11c2f03c82c8e0a1be183ff912a0e47a6a69098873ffb6610668bb30e2200885b9581bb9777bd02e1ac7
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
## v0.1.0 2015-07-12
|
2
|
+
|
3
|
+
### Changed (backward-incompatible)
|
4
|
+
|
5
|
+
* Renamed event-carried `data` to `attributes` (nepalez)
|
6
|
+
|
7
|
+
### Internal
|
8
|
+
|
9
|
+
* Switched to `ice_nine` gem to freezing objects deeply (nepalez)
|
10
|
+
* Switched to `hexx-suit` v2.3+ and `hexx-rspec` v0.5+ (nepalez)
|
11
|
+
|
12
|
+
[Compare v0.0.2...v0.1.0](https://github.com/nepalez/informator/compare/v0.0.2...v0.1.0)
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,7 @@ The [wisper]-inspired tiny implementation of publish/subscribe design pattern.
|
|
19
19
|
|
20
20
|
The implementation differs from the original wisper's approach in the following aspects:
|
21
21
|
|
22
|
-
* Unlike `Wisper::Publisher` that calls listener methods depending on the event, the `Informator` uses the same listener's callback for sending all events. Instead it wraps
|
22
|
+
* Unlike `Wisper::Publisher` that calls listener methods depending on the event, the `Informator` uses the same listener's callback for sending all events. Instead it wraps attributes to `Informator::Event` container and uses its as the argument for the callback.
|
23
23
|
|
24
24
|
* The `Informator` has two separate methods - `#remember` and `#publish`. The first one is used to build and collect events, while the second one publishes all unpublished events at once (and clears the list of events to be published).
|
25
25
|
|
@@ -44,7 +44,7 @@ The `Informator` module API defines 4 instance methods:
|
|
44
44
|
Except for the `Informator` the module defines public class `Informator::Event` for immutable events, that has 3 attributes:
|
45
45
|
|
46
46
|
* `#type` for symbolic type of the event
|
47
|
-
* `#
|
47
|
+
* `#attributes` for hash of attributes, carried by the event
|
48
48
|
* `#messages` for array of human-readable messages, describing the event
|
49
49
|
|
50
50
|
The event instance is build by the `#remember`, `#publish` or `#publish!` methods and is sent to listeners by either `#publish` or `#publish!`. When sending an event, the informator just calls the listeners callback, defined by `#subscribe` method, and gives it a corresponding event object as the only argument.
|
@@ -81,8 +81,8 @@ result = service.call
|
|
81
81
|
# The listener received success: ["for now all is fine"]
|
82
82
|
# The listener received error: ["OMG!"]
|
83
83
|
# => [
|
84
|
-
# #<Informator::Event @type=:success @
|
85
|
-
# #<Informator::Event @type=:error @
|
84
|
+
# #<Informator::Event @type=:success @attributes={ foo: :bar } @messages=["for now all is fine"]>,
|
85
|
+
# #<Informator::Event @type=:error @attributes={ bar: :baz } @messages=["OMG!"]>
|
86
86
|
# ]
|
87
87
|
|
88
88
|
```
|
data/Rakefile
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
6
|
-
exit
|
7
|
-
end
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler/setup"
|
8
5
|
|
9
6
|
# Loads bundler tasks
|
10
7
|
Bundler::GemHelper.install_tasks
|
@@ -23,5 +20,10 @@ task default: "test:coverage:run"
|
|
23
20
|
|
24
21
|
desc "Runs mutation metric for testing"
|
25
22
|
task :mutant do
|
26
|
-
system "mutant -r informator --use rspec
|
23
|
+
system "bundle exec mutant -r informator --use rspec Informator* --fail-fast"
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Exhort all evils"
|
27
|
+
task :mutant do
|
28
|
+
system "bundle exec mutant -r informator --use rspec Informator*"
|
27
29
|
end
|
data/informator.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.author = "Andrew Kozin"
|
9
9
|
gem.email = "andrew.kozin@gmail.com"
|
10
10
|
gem.homepage = "https://github.com/nepalez/informator"
|
11
|
-
gem.summary = "Implementation of subscribe
|
11
|
+
gem.summary = "Implementation of publish/subscribe design pattern"
|
12
12
|
gem.license = "MIT"
|
13
13
|
|
14
14
|
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
@@ -19,7 +19,8 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.required_ruby_version = "~> 2.1"
|
20
20
|
|
21
21
|
gem.add_runtime_dependency "equalizer", "~> 0.0"
|
22
|
+
gem.add_runtime_dependency "ice_nine", "~> 0.11"
|
22
23
|
|
23
|
-
gem.add_development_dependency "hexx-rspec", "~> 0.
|
24
|
+
gem.add_development_dependency "hexx-rspec", "~> 0.5"
|
24
25
|
|
25
26
|
end # Gem::Specification
|
data/lib/informator.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require "ice_nine"
|
3
4
|
require "equalizer"
|
4
5
|
|
5
6
|
require_relative "informator/event"
|
@@ -26,7 +27,7 @@ module Informator
|
|
26
27
|
self
|
27
28
|
end
|
28
29
|
|
29
|
-
# @!method remember(type, messages,
|
30
|
+
# @!method remember(type, messages, attributes)
|
30
31
|
# Builds and stores the event waiting for being published
|
31
32
|
#
|
32
33
|
# @param (see Informator::Event.new)
|
@@ -39,7 +40,7 @@ module Informator
|
|
39
40
|
self
|
40
41
|
end
|
41
42
|
|
42
|
-
# @overload publish(type, messages,
|
43
|
+
# @overload publish(type, messages, attributes)
|
43
44
|
# Builds the event and then publishes all unpublished events
|
44
45
|
#
|
45
46
|
# @param (see #remember)
|
@@ -56,7 +57,7 @@ module Informator
|
|
56
57
|
|
57
58
|
# The same as `publish` except for it throws `:published` afterwards
|
58
59
|
#
|
59
|
-
# @overload publish(type, messages,
|
60
|
+
# @overload publish(type, messages, attributes)
|
60
61
|
# Builds the event and then publishes all unpublished events
|
61
62
|
#
|
62
63
|
# @param (see #remember)
|
data/lib/informator/event.rb
CHANGED
@@ -2,22 +2,23 @@
|
|
2
2
|
|
3
3
|
module Informator
|
4
4
|
|
5
|
-
# Class Event provides an immutable container for hash of some
|
5
|
+
# Class Event provides an immutable container for hash of some attributes, to
|
6
6
|
# which a type is attached. It also contains an array of human-readable
|
7
7
|
# messages describing the event.
|
8
8
|
#
|
9
|
-
# The primary goal of events is folding
|
9
|
+
# The primary goal of events is folding attributes to be returned and/or sent
|
10
10
|
# between various objects into unified format.
|
11
11
|
#
|
12
12
|
# @example
|
13
13
|
# event = Event[:success, "bingo!", foo: :bar]
|
14
|
-
# #
|
14
|
+
# # <Event @type=:success @messages=["bingo!"] @attributes={ :foo => :bar }>
|
15
|
+
#
|
15
16
|
# event.frozen?
|
16
17
|
# # => true
|
17
18
|
#
|
18
19
|
class Event
|
19
20
|
|
20
|
-
include Equalizer.new(:type, :
|
21
|
+
include Equalizer.new(:type, :attributes)
|
21
22
|
|
22
23
|
# @!attribute [r] type
|
23
24
|
#
|
@@ -25,11 +26,11 @@ module Informator
|
|
25
26
|
#
|
26
27
|
attr_reader :type
|
27
28
|
|
28
|
-
# @!attribute [r]
|
29
|
+
# @!attribute [r] attributes
|
29
30
|
#
|
30
|
-
# @return [Hash] the event-specific
|
31
|
+
# @return [Hash] the event-specific attributes
|
31
32
|
#
|
32
|
-
attr_reader :
|
33
|
+
attr_reader :attributes
|
33
34
|
|
34
35
|
# @!attribute [r] messages
|
35
36
|
#
|
@@ -38,12 +39,12 @@ module Informator
|
|
38
39
|
attr_reader :messages
|
39
40
|
|
40
41
|
# @!scope class
|
41
|
-
# @!method [](type, messages,
|
42
|
+
# @!method [](type, messages, attributes)
|
42
43
|
# Builds the event
|
43
44
|
#
|
44
45
|
# @param [#to_sym] type
|
45
46
|
# @param [#to_s, Array<#to_s>] messages
|
46
|
-
# @param [Hash]
|
47
|
+
# @param [Hash] attributes
|
47
48
|
#
|
48
49
|
# @return [Informator::Event]
|
49
50
|
def self.[](*args)
|
@@ -51,11 +52,11 @@ module Informator
|
|
51
52
|
end
|
52
53
|
|
53
54
|
# @private
|
54
|
-
def initialize(type, *messages, **
|
55
|
-
@type
|
56
|
-
@messages
|
57
|
-
@
|
58
|
-
|
55
|
+
def initialize(type, *messages, **attributes)
|
56
|
+
@type = type.to_sym
|
57
|
+
@messages = messages.flatten.map(&:to_s)
|
58
|
+
@attributes = attributes
|
59
|
+
IceNine.deep_freeze(self)
|
59
60
|
end
|
60
61
|
|
61
62
|
end # class Event
|
data/lib/informator/reporter.rb
CHANGED
@@ -9,7 +9,7 @@ module Informator
|
|
9
9
|
# reporter.events # => []
|
10
10
|
#
|
11
11
|
# reporter.remember :success
|
12
|
-
# reporter.events # => [#<Event @type=:success @
|
12
|
+
# reporter.events # => [#<Event @type=:success @attributes={} @messages=[]>]
|
13
13
|
#
|
14
14
|
# # this will call subscriber.notify for any event
|
15
15
|
# reporter.notify subscriber
|
@@ -22,7 +22,7 @@ module Informator
|
|
22
22
|
# @private
|
23
23
|
def initialize
|
24
24
|
@events = []
|
25
|
-
freeze
|
25
|
+
freeze # freezes the instance, but left events mutable!
|
26
26
|
end
|
27
27
|
|
28
28
|
# @!attribute [r] events
|
@@ -30,7 +30,7 @@ module Informator
|
|
30
30
|
# the list of registered events that havent'b been published yet
|
31
31
|
attr_reader :events
|
32
32
|
|
33
|
-
# @!method remember(type, messages,
|
33
|
+
# @!method remember(type, messages, attributes)
|
34
34
|
# Registers the event to be published to subscribers
|
35
35
|
#
|
36
36
|
# @param (see Informator::Event.new)
|
@@ -59,7 +59,7 @@ module Informator
|
|
59
59
|
|
60
60
|
def publish(subscribers)
|
61
61
|
event = events.shift
|
62
|
-
subscribers.each { |subscriber| subscriber.notify
|
62
|
+
subscribers.each { |subscriber| subscriber.notify(event) }
|
63
63
|
end
|
64
64
|
|
65
65
|
end # class Reporter
|
@@ -11,11 +11,11 @@ module Informator
|
|
11
11
|
# subscriber.frozen? # => true
|
12
12
|
#
|
13
13
|
# event = Informator::Event.new :success
|
14
|
-
# # => #<Event @type=:success @
|
14
|
+
# # => #<Event @type=:success @attributes={} @messages=[]>
|
15
15
|
#
|
16
16
|
# subscriber.notify event
|
17
17
|
# object.event
|
18
|
-
# # => #<Event @type=:success @
|
18
|
+
# # => #<Event @type=:success @attributes={} @messages=[]>
|
19
19
|
#
|
20
20
|
# @api private
|
21
21
|
#
|
@@ -48,7 +48,7 @@ module Informator
|
|
48
48
|
def initialize(object, callback = :receive)
|
49
49
|
@object = object
|
50
50
|
@callback = callback.to_sym
|
51
|
-
|
51
|
+
IceNine.deep_freeze(self)
|
52
52
|
end
|
53
53
|
|
54
54
|
# Sends the event to the subscriber object via its callback
|
data/lib/informator/version.rb
CHANGED
@@ -37,18 +37,18 @@ describe Informator::Event do
|
|
37
37
|
|
38
38
|
end # describe #messages
|
39
39
|
|
40
|
-
describe "#
|
40
|
+
describe "#attributes" do
|
41
41
|
|
42
|
-
subject { event.
|
42
|
+
subject { event.attributes }
|
43
43
|
it { is_expected.to eq(baz: :qux) }
|
44
44
|
|
45
|
-
end # describe #
|
45
|
+
end # describe #attributes
|
46
46
|
|
47
47
|
describe "#==" do
|
48
48
|
|
49
49
|
subject { event == other }
|
50
50
|
|
51
|
-
context "to event with the same type and
|
51
|
+
context "to event with the same type and attributes" do
|
52
52
|
|
53
53
|
let(:other) { Class.new(described_class).new type, baz: :qux }
|
54
54
|
it { is_expected.to eql true }
|
@@ -62,7 +62,7 @@ describe Informator::Event do
|
|
62
62
|
|
63
63
|
end # context
|
64
64
|
|
65
|
-
context "to event with other
|
65
|
+
context "to event with other attributes" do
|
66
66
|
|
67
67
|
let(:other) { described_class.new :success, baz: "qux" }
|
68
68
|
it { is_expected.to eql false }
|
@@ -4,7 +4,7 @@ describe Informator::Subscriber do
|
|
4
4
|
|
5
5
|
let(:callback) { "foo" }
|
6
6
|
let(:event) { double }
|
7
|
-
let(:object) { double callback.to_sym => callback }
|
7
|
+
let(:object) { double callback.to_sym => callback, freeze: nil }
|
8
8
|
|
9
9
|
subject(:subscriber) { described_class.new object, callback }
|
10
10
|
|
@@ -61,12 +61,12 @@ describe Informator::Subscriber do
|
|
61
61
|
|
62
62
|
context "to event with another object" do
|
63
63
|
|
64
|
-
let(:other) {
|
64
|
+
let(:other) { double freeze: nil }
|
65
65
|
it { is_expected.to eql false }
|
66
66
|
|
67
67
|
end # context
|
68
68
|
|
69
|
-
context "to event with other
|
69
|
+
context "to event with other attributes" do
|
70
70
|
|
71
71
|
let(:other) { described_class.new object, :other }
|
72
72
|
it { is_expected.to eql false }
|
@@ -7,7 +7,13 @@ describe Informator do
|
|
7
7
|
let(:klass) { Class.new { include Informator } }
|
8
8
|
let(:callback) { :on_received }
|
9
9
|
let(:listener) do
|
10
|
-
double
|
10
|
+
double(
|
11
|
+
callback => nil,
|
12
|
+
foo: nil,
|
13
|
+
bar: nil,
|
14
|
+
receive: nil,
|
15
|
+
freeze: nil
|
16
|
+
)
|
11
17
|
end
|
12
18
|
|
13
19
|
before { informator.subscribe listener, callback }
|
@@ -67,7 +73,7 @@ describe Informator do
|
|
67
73
|
expect(event).to be_kind_of Informator::Event
|
68
74
|
expect(event.type).to eq :alert
|
69
75
|
expect(event.messages).to eql %w(foo)
|
70
|
-
expect(event.
|
76
|
+
expect(event.attributes).to eql(bar: :baz)
|
71
77
|
end
|
72
78
|
|
73
79
|
informator.publish :alert, "foo", bar: :baz
|
@@ -129,7 +135,7 @@ describe Informator do
|
|
129
135
|
end
|
130
136
|
|
131
137
|
it "throws :published" do
|
132
|
-
expect { informator.publish! }.to raise_error
|
138
|
+
expect { informator.publish! }.to raise_error(ArgumentError)
|
133
139
|
expect { catch(:published) { informator.publish! } }.not_to raise_error
|
134
140
|
end
|
135
141
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: informator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equalizer
|
@@ -24,20 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ice_nine
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.11'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.11'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: hexx-rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
47
|
+
version: '0.5'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
54
|
+
version: '0.5'
|
41
55
|
description:
|
42
56
|
email: andrew.kozin@gmail.com
|
43
57
|
executables: []
|
@@ -76,11 +90,11 @@ files:
|
|
76
90
|
- lib/informator/reporter.rb
|
77
91
|
- lib/informator/subscriber.rb
|
78
92
|
- lib/informator/version.rb
|
79
|
-
- spec/integration/informator_spec.rb
|
80
93
|
- spec/spec_helper.rb
|
81
94
|
- spec/unit/informator/event_spec.rb
|
82
95
|
- spec/unit/informator/reporter_spec.rb
|
83
96
|
- spec/unit/informator/subscriber_spec.rb
|
97
|
+
- spec/unit/informator_spec.rb
|
84
98
|
homepage: https://github.com/nepalez/informator
|
85
99
|
licenses:
|
86
100
|
- MIT
|
@@ -104,10 +118,10 @@ rubyforge_project:
|
|
104
118
|
rubygems_version: 2.4.6
|
105
119
|
signing_key:
|
106
120
|
specification_version: 4
|
107
|
-
summary: Implementation of subscribe
|
121
|
+
summary: Implementation of publish/subscribe design pattern
|
108
122
|
test_files:
|
109
123
|
- spec/spec_helper.rb
|
110
|
-
- spec/
|
124
|
+
- spec/unit/informator_spec.rb
|
111
125
|
- spec/unit/informator/event_spec.rb
|
112
126
|
- spec/unit/informator/reporter_spec.rb
|
113
127
|
- spec/unit/informator/subscriber_spec.rb
|