informator 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/informator.gemspec +2 -0
- data/lib/informator.rb +2 -0
- data/lib/informator/event.rb +6 -23
- data/lib/informator/subscriber.rb +1 -21
- data/lib/informator/version.rb +1 -1
- data/spec/unit/informator/event_spec.rb +11 -1
- data/spec/unit/informator/subscriber_spec.rb +0 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 341da250ea78c55d21c12821a7cc8e91af9ed07b
|
4
|
+
data.tar.gz: dfa16302f4547fe123631d9dae3737fb960ca448
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21f6b276db2537b24a2012be0b9b03fc6522e760c80daf8aaef7cdf5f4e335677588712df378b33f1b6cc009e183be84a8f500c44651215776fd49d9ad55c25e
|
7
|
+
data.tar.gz: 1d19b1c9e78ec72579d1b931906302d2a5bb5f0a2e14a8b845f5f71b814933ee11c514c891b5858e7672b0bf47ee213c4e9e53e5d377d14556b7f43c50498021
|
data/informator.gemspec
CHANGED
data/lib/informator.rb
CHANGED
data/lib/informator/event.rb
CHANGED
@@ -10,14 +10,14 @@ module Informator
|
|
10
10
|
# between various objects into unified format.
|
11
11
|
#
|
12
12
|
# @example
|
13
|
-
# event = Event
|
13
|
+
# event = Event[:success, "bingo!", foo: :bar]
|
14
14
|
# # => #<Event @type=:success, @messages=["bingo!"], @data={ :foo => :bar }>
|
15
15
|
# event.frozen?
|
16
16
|
# # => true
|
17
17
|
#
|
18
18
|
class Event
|
19
19
|
|
20
|
-
include
|
20
|
+
include Equalizer.new(:type, :data)
|
21
21
|
|
22
22
|
# @!attribute [r] type
|
23
23
|
#
|
@@ -38,7 +38,7 @@ module Informator
|
|
38
38
|
attr_reader :messages
|
39
39
|
|
40
40
|
# @!scope class
|
41
|
-
# @!method
|
41
|
+
# @!method [](type, messages, data)
|
42
42
|
# Builds the event
|
43
43
|
#
|
44
44
|
# @param [#to_sym] type
|
@@ -46,6 +46,9 @@ module Informator
|
|
46
46
|
# @param [Hash] data
|
47
47
|
#
|
48
48
|
# @return [Informator::Event]
|
49
|
+
def self.[](*args)
|
50
|
+
new(*args)
|
51
|
+
end
|
49
52
|
|
50
53
|
# @private
|
51
54
|
def initialize(type, *messages, **data)
|
@@ -55,26 +58,6 @@ module Informator
|
|
55
58
|
freeze
|
56
59
|
end
|
57
60
|
|
58
|
-
# Compares the event to another one by their types and data
|
59
|
-
#
|
60
|
-
# @param [Object] other
|
61
|
-
#
|
62
|
-
# @return [Boolean]
|
63
|
-
#
|
64
|
-
def ==(other)
|
65
|
-
other.is_a?(self.class) && other.value.eql?(value)
|
66
|
-
end
|
67
|
-
|
68
|
-
protected
|
69
|
-
|
70
|
-
# Returns value to compare events by
|
71
|
-
#
|
72
|
-
# @return [Array]
|
73
|
-
#
|
74
|
-
def value
|
75
|
-
[type, data]
|
76
|
-
end
|
77
|
-
|
78
61
|
end # class Event
|
79
62
|
|
80
63
|
end # module Informator
|
@@ -21,7 +21,7 @@ module Informator
|
|
21
21
|
#
|
22
22
|
class Subscriber
|
23
23
|
|
24
|
-
include
|
24
|
+
include Equalizer.new(:object, :callback)
|
25
25
|
|
26
26
|
# @!attribute [r] object
|
27
27
|
#
|
@@ -63,26 +63,6 @@ module Informator
|
|
63
63
|
event
|
64
64
|
end
|
65
65
|
|
66
|
-
# Compares the subscriber to another one by their objects and callbacks
|
67
|
-
#
|
68
|
-
# @param [Object] other
|
69
|
-
#
|
70
|
-
# @return [Boolean]
|
71
|
-
#
|
72
|
-
def ==(other)
|
73
|
-
other.instance_of?(self.class) ? other.value.eql?(value) : false
|
74
|
-
end
|
75
|
-
|
76
|
-
protected
|
77
|
-
|
78
|
-
# Returns value to compare subscribers by
|
79
|
-
#
|
80
|
-
# @return [Array]
|
81
|
-
#
|
82
|
-
def value
|
83
|
-
[object, callback]
|
84
|
-
end
|
85
|
-
|
86
66
|
end # class Subscriber
|
87
67
|
|
88
68
|
end # module Informator
|
data/lib/informator/version.rb
CHANGED
@@ -8,11 +8,21 @@ describe Informator::Event do
|
|
8
8
|
|
9
9
|
describe ".new" do
|
10
10
|
|
11
|
-
it { is_expected.to be_kind_of Comparable }
|
12
11
|
it { is_expected.to be_frozen }
|
13
12
|
|
14
13
|
end # describe .new
|
15
14
|
|
15
|
+
describe ".[]" do
|
16
|
+
|
17
|
+
before { allow(described_class).to receive(:new) }
|
18
|
+
|
19
|
+
it "builds the event" do
|
20
|
+
expect(described_class).to receive(:new).with(:foo, :bar, :baz)
|
21
|
+
described_class[:foo, :bar, :baz]
|
22
|
+
end
|
23
|
+
|
24
|
+
end # describe .new
|
25
|
+
|
16
26
|
describe "#type" do
|
17
27
|
|
18
28
|
subject { event.type }
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: informator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-05
|
11
|
+
date: 2015-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: equalizer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: hexx-rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|