ventable 0.0.6 → 1.0.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/.atom-build.json +10 -0
- data/.gitignore +0 -1
- data/.rspec +2 -0
- data/Gemfile.lock +72 -0
- data/README.md +1 -1
- data/lib/ventable/version.rb +1 -1
- data/spec/ventable/ventable_spec.rb +39 -41
- data/ventable.gemspec +1 -0
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d49bbdbaf27b03c942ba8887eb4eca4c89f63cbc
|
4
|
+
data.tar.gz: c75ae281c96bfa5998c6f338ba5fd6d5bb164ace
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d130ab305df24c7f31e1fc11dcf7cc64c560edd2311ff6330ebeb33394ed819e444795b8f6c5fb3aff8ba9371c96c746dbec17db3ac3b368a149891bde5fc0c
|
7
|
+
data.tar.gz: 2f12228bb3d42a58d7534f077844b26c5f1212c104b5da2bbf8aa4facb2f1783f86cfa1abc10e8b08982cbcfd6a07efbd6dd8f8afb9e76e42ecd271e06f07887
|
data/.atom-build.json
ADDED
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ventable (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.0)
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
ffi (1.9.10)
|
12
|
+
formatador (0.2.5)
|
13
|
+
guard (2.13.0)
|
14
|
+
formatador (>= 0.2.4)
|
15
|
+
listen (>= 2.7, <= 4.0)
|
16
|
+
lumberjack (~> 1.0)
|
17
|
+
nenv (~> 0.1)
|
18
|
+
notiffany (~> 0.0)
|
19
|
+
pry (>= 0.9.12)
|
20
|
+
shellany (~> 0.0)
|
21
|
+
thor (>= 0.18.1)
|
22
|
+
guard-compat (1.2.1)
|
23
|
+
guard-rspec (4.6.4)
|
24
|
+
guard (~> 2.1)
|
25
|
+
guard-compat (~> 1.1)
|
26
|
+
rspec (>= 2.99.0, < 4.0)
|
27
|
+
listen (3.0.5)
|
28
|
+
rb-fsevent (>= 0.9.3)
|
29
|
+
rb-inotify (>= 0.9)
|
30
|
+
lumberjack (1.0.10)
|
31
|
+
method_source (0.8.2)
|
32
|
+
nenv (0.2.0)
|
33
|
+
notiffany (0.0.8)
|
34
|
+
nenv (~> 0.1)
|
35
|
+
shellany (~> 0.0)
|
36
|
+
pry (0.10.3)
|
37
|
+
coderay (~> 1.1.0)
|
38
|
+
method_source (~> 0.8.1)
|
39
|
+
slop (~> 3.4)
|
40
|
+
rake (10.5.0)
|
41
|
+
rb-fsevent (0.9.7)
|
42
|
+
rb-inotify (0.9.5)
|
43
|
+
ffi (>= 0.5.0)
|
44
|
+
rspec (3.4.0)
|
45
|
+
rspec-core (~> 3.4.0)
|
46
|
+
rspec-expectations (~> 3.4.0)
|
47
|
+
rspec-mocks (~> 3.4.0)
|
48
|
+
rspec-core (3.4.1)
|
49
|
+
rspec-support (~> 3.4.0)
|
50
|
+
rspec-expectations (3.4.0)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.4.0)
|
53
|
+
rspec-mocks (3.4.1)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.4.0)
|
56
|
+
rspec-support (3.4.1)
|
57
|
+
shellany (0.0.1)
|
58
|
+
slop (3.6.0)
|
59
|
+
thor (0.19.1)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
guard-rspec
|
66
|
+
rake
|
67
|
+
rspec
|
68
|
+
rspec-mocks
|
69
|
+
ventable!
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
1.11.2
|
data/README.md
CHANGED
@@ -184,7 +184,7 @@ via a background queue, such as Sidekiq or Resque. If you are interested in help
|
|
184
184
|
|
185
185
|
For more information, check out the following blog post:
|
186
186
|
|
187
|
-
[Detangling Business Logic in Rails Apps with Pure Ruby Observers](http://building.wanelo.com/
|
187
|
+
[Detangling Business Logic in Rails Apps with Pure Ruby Observers](http://building.wanelo.com/2013/08/05/detangling-business-logic-in-rails-apps-with-poro-events-and-observers.html).
|
188
188
|
|
189
189
|
## Contributing
|
190
190
|
|
data/lib/ventable/version.rb
CHANGED
@@ -11,25 +11,25 @@ describe Ventable do
|
|
11
11
|
after { Ventable.enable }
|
12
12
|
|
13
13
|
it 'is true by default' do
|
14
|
-
expect(Ventable.enabled?).to
|
14
|
+
expect(Ventable.enabled?).to be true
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'is false after Ventable is disabled' do
|
18
18
|
Ventable.disable
|
19
|
-
expect(Ventable.enabled?).to
|
19
|
+
expect(Ventable.enabled?).to be false
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'is true after Ventable is re-enabled' do
|
23
23
|
Ventable.disable
|
24
24
|
Ventable.enable
|
25
|
-
expect(Ventable.enabled?).to
|
25
|
+
expect(Ventable.enabled?).to be true
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "including Ventable::Event" do
|
30
30
|
it "should create a class instance variable to keep observers" do
|
31
|
-
TestEvent.observers.
|
32
|
-
TestEvent.observers.
|
31
|
+
expect(TestEvent.observers).not_to be_nil
|
32
|
+
expect(TestEvent.observers.class.name).to eq("Set")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should see observers variable from instance methods" do
|
@@ -37,14 +37,14 @@ describe Ventable do
|
|
37
37
|
TestEvent.new.instance_eval do
|
38
38
|
observers = self.class.observers
|
39
39
|
end
|
40
|
-
observers.
|
40
|
+
expect(observers).to_not be_nil
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should maintain separate sets of observers for each event" do
|
44
44
|
class AnotherEvent
|
45
45
|
include Ventable::Event
|
46
46
|
end
|
47
|
-
AnotherEvent.observers.object_id.
|
47
|
+
expect(AnotherEvent.observers.object_id).to_not eq(TestEvent.observers.object_id)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -62,38 +62,37 @@ describe Ventable do
|
|
62
62
|
run_block = true
|
63
63
|
event = e
|
64
64
|
end
|
65
|
-
run_block.
|
66
|
-
event.
|
65
|
+
expect(run_block).to eq(false)
|
66
|
+
expect(event).to be_nil
|
67
67
|
|
68
68
|
# fire the event
|
69
69
|
TestEvent.new.fire!
|
70
70
|
|
71
|
-
run_block.
|
72
|
-
event.
|
71
|
+
expect(run_block).to be true
|
72
|
+
expect(event).not_to be_nil
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should properly call a class observer" do
|
76
|
-
TestEvent
|
76
|
+
class TestEvent
|
77
77
|
class << self
|
78
78
|
attr_accessor :flag
|
79
79
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
def set_flag!
|
84
|
-
self.class.flag = true
|
80
|
+
self.flag = "unset"
|
81
|
+
def flag= value
|
82
|
+
self.class.flag = value
|
85
83
|
end
|
86
84
|
end
|
85
|
+
|
87
86
|
class TestEventObserver
|
88
87
|
def self.handle_test event
|
89
|
-
event.
|
88
|
+
event.flag = "boo"
|
90
89
|
end
|
91
90
|
end
|
92
91
|
TestEvent.notifies TestEventObserver
|
93
|
-
TestEvent.flag.
|
92
|
+
expect(TestEvent.flag).to eq("unset")
|
94
93
|
|
95
94
|
TestEvent.new.fire!
|
96
|
-
TestEvent.flag.
|
95
|
+
expect(TestEvent.flag).to eq("boo")
|
97
96
|
end
|
98
97
|
|
99
98
|
it "should properly call a group of observers" do
|
@@ -118,19 +117,18 @@ describe Ventable do
|
|
118
117
|
event_inside = event
|
119
118
|
end
|
120
119
|
|
121
|
-
transaction_called.
|
122
|
-
transaction_already_completed.
|
123
|
-
observer_block_called.
|
120
|
+
expect(transaction_called).to be false
|
121
|
+
expect(transaction_already_completed).to be false
|
122
|
+
expect(observer_block_called).to be false
|
124
123
|
|
125
124
|
TestEvent.new.fire!
|
126
125
|
|
127
|
-
transaction_called.
|
128
|
-
observer_block_called.
|
129
|
-
transaction_called.
|
130
|
-
transaction_already_completed.
|
131
|
-
|
132
|
-
event_inside.
|
133
|
-
event_inside.should be_a(TestEvent)
|
126
|
+
expect(transaction_called).to be true
|
127
|
+
expect(observer_block_called).to be true
|
128
|
+
expect(transaction_called).to be true
|
129
|
+
expect(transaction_already_completed).to be false
|
130
|
+
expect(event_inside).to_not be_nil
|
131
|
+
expect(event_inside).to be_a(TestEvent)
|
134
132
|
end
|
135
133
|
|
136
134
|
context 'when globally disabled' do
|
@@ -145,7 +143,7 @@ describe Ventable do
|
|
145
143
|
end
|
146
144
|
|
147
145
|
TestEvent.new.fire!
|
148
|
-
expect(observers_notified).to
|
146
|
+
expect(observers_notified).to be false
|
149
147
|
end
|
150
148
|
end
|
151
149
|
end
|
@@ -175,15 +173,15 @@ describe Ventable do
|
|
175
173
|
end
|
176
174
|
|
177
175
|
it "should properly set the callback method name" do
|
178
|
-
SomeAwesomeEvent.default_callback_method.
|
179
|
-
Blah::AnotherSweetEvent.default_callback_method.
|
180
|
-
SomeOtherStuffHappened.default_callback_method.
|
181
|
-
ClassWithCustomCallbackMethodEvent.default_callback_method.
|
176
|
+
expect(SomeAwesomeEvent.default_callback_method).to eq(:handle_some_awesome)
|
177
|
+
expect(Blah::AnotherSweetEvent.default_callback_method).to eq(:handle_blah__another_sweet)
|
178
|
+
expect(SomeOtherStuffHappened.default_callback_method).to eq(:handle_some_other_stuff_happened)
|
179
|
+
expect(ClassWithCustomCallbackMethodEvent.default_callback_method).to eq(:handle_my_special_event)
|
182
180
|
end
|
183
181
|
end
|
184
182
|
|
185
183
|
describe "#configure" do
|
186
|
-
it "properly configures the event with
|
184
|
+
it "properly configures the event with observers" do
|
187
185
|
notified_observer = false
|
188
186
|
TestEvent.configure do
|
189
187
|
notifies do
|
@@ -191,7 +189,7 @@ describe Ventable do
|
|
191
189
|
end
|
192
190
|
end
|
193
191
|
TestEvent.new.fire!
|
194
|
-
notified_observer.
|
192
|
+
expect(notified_observer).to be true
|
195
193
|
end
|
196
194
|
|
197
195
|
it "configures observers with groups" do
|
@@ -207,8 +205,8 @@ describe Ventable do
|
|
207
205
|
end
|
208
206
|
end
|
209
207
|
TestEvent.new.fire!
|
210
|
-
notified_observer.
|
211
|
-
called_transaction.
|
208
|
+
expect(notified_observer).to be true
|
209
|
+
expect(called_transaction).to be true
|
212
210
|
end
|
213
211
|
|
214
212
|
it "throws exception if :inside references unknown group" do
|
@@ -220,7 +218,7 @@ describe Ventable do
|
|
220
218
|
end
|
221
219
|
fail "Shouldn't reach here, must throw a valid exception"
|
222
220
|
rescue Exception => e
|
223
|
-
e.class.
|
221
|
+
expect(e.class).to eq(Ventable::Error)
|
224
222
|
end
|
225
223
|
end
|
226
224
|
it "throws exception if nil observer added to the list" do
|
@@ -230,7 +228,7 @@ describe Ventable do
|
|
230
228
|
end
|
231
229
|
fail "Shouldn't reach here, must throw a valid exception"
|
232
230
|
rescue Exception => e
|
233
|
-
e.class.
|
231
|
+
expect(e.class).to eq(Ventable::Error)
|
234
232
|
end
|
235
233
|
end
|
236
234
|
end
|
data/ventable.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.require_paths = ["lib"]
|
17
17
|
gem.version = Ventable::VERSION
|
18
18
|
|
19
|
+
gem.add_development_dependency "rake"
|
19
20
|
gem.add_development_dependency "rspec"
|
20
21
|
gem.add_development_dependency "rspec-mocks"
|
21
22
|
gem.add_development_dependency 'guard-rspec'
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ventable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Gredeskoul
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,10 +73,12 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- ".atom-build.json"
|
62
77
|
- ".gitignore"
|
63
78
|
- ".rspec"
|
64
79
|
- ".travis.yml"
|
65
80
|
- Gemfile
|
81
|
+
- Gemfile.lock
|
66
82
|
- Guardfile
|
67
83
|
- LICENSE
|
68
84
|
- README.md
|
@@ -92,11 +108,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
108
|
version: '0'
|
93
109
|
requirements: []
|
94
110
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.5.1
|
96
112
|
signing_key:
|
97
113
|
specification_version: 4
|
98
114
|
summary: Event/Observable design pattern in ruby
|
99
115
|
test_files:
|
100
116
|
- spec/spec_helper.rb
|
101
117
|
- spec/ventable/ventable_spec.rb
|
102
|
-
has_rdoc:
|