ventable 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d49bbdbaf27b03c942ba8887eb4eca4c89f63cbc
4
- data.tar.gz: c75ae281c96bfa5998c6f338ba5fd6d5bb164ace
2
+ SHA256:
3
+ metadata.gz: 57b42bb96d2c3c0bac1f4fc8e97ed42b3ee5eb9494a9f36f04cea0c0888765e3
4
+ data.tar.gz: 13b3f1b9860d9b26b812bf0ff6b2daa4d318af0906d71d4e02a17577067e7eca
5
5
  SHA512:
6
- metadata.gz: 7d130ab305df24c7f31e1fc11dcf7cc64c560edd2311ff6330ebeb33394ed819e444795b8f6c5fb3aff8ba9371c96c746dbec17db3ac3b368a149891bde5fc0c
7
- data.tar.gz: 2f12228bb3d42a58d7534f077844b26c5f1212c104b5da2bbf8aa4facb2f1783f86cfa1abc10e8b08982cbcfd6a07efbd6dd8f8afb9e76e42ecd271e06f07887
6
+ metadata.gz: 2a032511c88f1f9f2f62f2a0b3b39a2f81337585550596634eabb875c34731bfe458477a4246e47e2624363041fccb92fc6e98b7628d5e4bb32a6a62ab058511
7
+ data.tar.gz: 396af327f6e393cc9db4efd5f12c2787eeec7fa2cb1f83f9c600e389bd8296bb3092713a5e9056b252acd9e1129e5703853e0099cc82f9a58646c0bc5b1532a0
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ **/.DS_Store
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
@@ -5,6 +6,7 @@
5
6
  .yardoc
6
7
  InstalledFiles
7
8
  _yardoc
9
+ Gemfile.lock
8
10
  coverage
9
11
  doc/
10
12
  lib/bundler/man
@@ -15,3 +17,4 @@ test/tmp
15
17
  test/version_tmp
16
18
  tmp
17
19
  .idea/
20
+ vendor/
@@ -1,10 +1,18 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- script: "bundle exec rspec"
5
- notifications:
6
- email:
7
- recipients:
8
- - kigster@gmail.com
9
- on_success: never
10
- on_failure: always
3
+ - 2.3.8
4
+ - 2.4.5
5
+ - 2.5.3
6
+ - 2.6.1
7
+ script:
8
+ - bundle exec rspec
9
+ env:
10
+ global:
11
+ - secure: mjjlvfSCJpmD06E5DIkqhaYwjGP85cyBeM8NrxLsUXuEYLVNvL8pKoL5GJVPE8oqnQ93j2egLXZw50ZER7rBWDJhdHZ1LosQEKJgljRNc/wjqyQBTXRr3ZBRpWxKO4SJMhM65lUp1UYzIQj8AJDNehuZIIngFBTy01sHsI+hs8g=
12
+ before_script:
13
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
14
+ > ./cc-test-reporter
15
+ - chmod +x ./cc-test-reporter
16
+ - "./cc-test-reporter before-build"
17
+ after_script:
18
+ - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in ventable.gemspec
4
2
  gemspec
data/README.md CHANGED
@@ -1,14 +1,47 @@
1
- [![Gem Version](https://badge.fury.io/rb/ventable.png)](http://badge.fury.io/rb/ventable)
2
- [![Build status](https://secure.travis-ci.org/kigster/ventable.png)](http://travis-ci.org/kigster/ventable)
3
- [![Code Climate](https://codeclimate.com/github/kigster/ventable.png)](https://codeclimate.com/github/kigster/ventable)
1
+
2
+ [![Gem Version](https://badge.fury.io/rb/ventable.svg)](https://badge.fury.io/rb/ventable)
3
+ [![Build Status](https://travis-ci.org/kigster/ventable.svg?branch=master)](https://travis-ci.org/kigster/ventable)
4
+ [![Code Climate](https://codeclimate.com/github/kigster/ventable/badges/gpa.svg)](https://codeclimate.com/github/kigster/ventable)
5
+ [![Downloads](http://ruby-gem-downloads-badge.herokuapp.com/ventable?type=total)](https://rubygems.org/gems/ventable)
6
+ [![Gitter](https://img.shields.io/gitter/room/gitterHQ/gitter.svg)](https://gitter.im/kigster/ventable)
7
+
8
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c28d141c978293886d21/test_coverage)](https://codeclimate.com/github/kigster/ventable/test_coverage)
4
9
 
5
10
 
6
11
  # Ventable
7
12
 
8
- Simple eventing gem that implements Observable pattern, but with more options, ability to group observers and wrap
9
- them in arbitrary blocks of code. For example, when a certain event fires, some observers may be called within
10
- a transaction context, while others maybe called outside of the transaction context.
13
+ This gem is a variation of the [Observer Design Pattern](https://en.wikipedia.org/wiki/Observer_pattern).
14
+
15
+ In particular:
16
+
17
+ * Ventable requires creation of simple event classes that may carry data and be serialized.
18
+ * Observers can be grouped together, and notified within a pre-defined `Proc`. For example, using grouping some observers may be called within the boundaries of a database transaction, while others maybe called outside of it.
19
+ * Ventable allows both compile time and run time observer binding.
20
+ * Ventable calls specific method on each observer, using automatically derived method name from the event class. A generic `#handle_event` method is also supported.
21
+
22
+ Limitations:
23
+
24
+ * At the moment, Ventable can only notify observers within the current ruby process.
25
+
26
+ ## Plugins
27
+
28
+ Ventable has several plugins that add various functionality on top of the basic event dispatch mechanism.
11
29
 
30
+ * [ventable-statsd](https://github.com/kigster/ventable-statsd) is an extension that allows notifying Statsd whenever an event occurs.
31
+ * [simple-feed](https://github.com/kigster/simple-feed) is a generic implementation of the activity feed concept commonly seen on social networks, and it integrates nicely with Ventable.
32
+
33
+ ## Ruby Versions
34
+
35
+ This gem has been verified to work in the following ruby versions:
36
+
37
+ * MRI Ruby
38
+ * 1.9.3-p551
39
+ * 2.2
40
+ * 2.3
41
+ * 2.4
42
+
43
+ The gem also likely works with non-MRI rubies, but it has not been tested.
44
+
12
45
  ## Installation
13
46
 
14
47
  Add this line to your application's Gemfile:
@@ -25,13 +58,16 @@ Or install it yourself as:
25
58
 
26
59
  ## Usage
27
60
 
28
- 1. Create your own plain ruby Event class that optionally carries some data important to the event. Include module ```Ventable::Event```.
61
+ 1. Create your own plain ruby Event class that optionally carries some data important to the event. Include module `Ventable::Event`.
62
+
29
63
  2. Create one or more observers. Observer can be any class that implements event handler method as a class method, such as a
30
- generic method ```self.handle(event)``` or a more specific method mapped to the event name: say for event UserRegistered the
31
- callback event would be ```self.handle_user_registered(event)```
32
- 3. Register your observers with the event using ```notifies``` event method, or register groups using ```group``` method, and then
33
- use ```notify``` with options ```inside: :group_name```
34
- 4. Instantiate your event class (optionally with some data), and call ```fire!``` method.
64
+ generic method `self.handle(event)` or a more specific method mapped to the event name: say for event UserRegistered the
65
+ callback event would be `self.handle_user_registered(event)`
66
+
67
+ 3. Register your observers with the event using `notifies` event method, or register groups using `group` method, and then
68
+ use `notify` with options `inside: :group_name`
69
+
70
+ 4. Instantiate your event class (optionally with some data), and call `publish` or, a deprecated `fire!` method.
35
71
 
36
72
  ## Example
37
73
 
@@ -62,7 +98,7 @@ end
62
98
  AlarmSoundEvent.notifies SleepingPerson
63
99
 
64
100
  # Create and fire the event
65
- AlarmSoundEvent.new(Date.new).fire!
101
+ AlarmSoundEvent.new(Date.new).publish
66
102
  ```
67
103
 
68
104
  ## Using #configure and groups
@@ -101,7 +137,7 @@ SomeEvent.configure do
101
137
  notifies ObserverClass1, ObserverClass2, inside: :transaction
102
138
  end
103
139
 
104
- SomeEvent.new.fire!
140
+ SomeEvent.new.publish
105
141
  ```
106
142
 
107
143
  ## Callback Method Name
@@ -119,23 +155,23 @@ using the following logic:
119
155
 
120
156
  You should start by defining your event library for your application (list of events
121
157
  that are important to you), you can place these files anywhere you like, such as
122
- ```lib/events``` or ```app/events```, etc.
158
+ `lib/events` or `app/events`, etc.
123
159
 
124
- It is recommended to ```configure``` all events and their observers in the ```event_initializer.rb``` file,
125
- inside the ```config/ininitalizers``` folder. You may need to require your events in that file also.
160
+ It is recommended to `configure` all events and their observers in the `event_initializer.rb` file,
161
+ inside the `config/ininitalizers` folder. You may need to require your events in that file also.
126
162
 
127
163
  When your event is tied to a creation of a "first class objects", such as user registration,
128
164
  it is recommended to create the User record first, commit it to the database, and then throw
129
- a ```UserRegisteredEvent.new(user).fire!```, and have all subsequent logic broeken into
130
- their respective classes. For example, if you need to send an email to the user, have a ```Mailer```
131
- class observe the ```UserRegisteredEvent```, and so all the mailing logic can live inside the ```Mailer```
132
- class, instead of, say, registration controller directly calling ```Mailer.deliver_user_registration!(user)```.
165
+ a `UserRegisteredEvent.new(user).publish`, and have all subsequent logic broeken into
166
+ their respective classes. For example, if you need to send an email to the user, have a `Mailer`
167
+ class observe the `UserRegisteredEvent`, and so all the mailing logic can live inside the `Mailer`
168
+ class, instead of, say, registration controller directly calling `Mailer.deliver_user_registration!(user)`.
133
169
  The callback method will receive the event, that wraps the User instance, or any other useful data necessary.
134
170
 
135
171
  ## Integration with tests
136
172
 
137
173
  There are times when it may be desirable to disable all eventing. For instance, when writing unit tests,
138
- testing that events are fired may be useful, but integrating with all observers adds complexity and confusion.
174
+ testing that events are published may be useful, but integrating with all observers adds complexity and confusion.
139
175
  In these cases, Ventable may be globally disabled.
140
176
 
141
177
  ```ruby
@@ -153,14 +189,14 @@ Now in a spec file:
153
189
  ```ruby
154
190
  describe "Stuff", eventing: false do
155
191
  it 'does stuff' do
156
- ... my code that fires events, in isolation from event observers
192
+ ... my code that publishes events, in isolation from event observers
157
193
  end
158
194
 
159
- it 'tests that events are fired, using stubs' do
160
- event = double(fire!: true)
195
+ it 'tests that events are published, using stubs' do
196
+ event = double(publish: true)
161
197
  allow(MyEvent).to receive(:new).and_return(event)
162
198
  ... my code that should fire event
163
- expect(event).to have_received(:fire!)
199
+ expect(event).to have_received(:publish)
164
200
  end
165
201
  end
166
202
 
data/Rakefile CHANGED
@@ -1,3 +1,22 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+
3
+ def shell(*args)
4
+ puts "running: #{args.join(' ')}"
5
+ system(args.join(' '))
6
+ end
7
+
8
+ task :clean do
9
+ shell('rm -rf pkg/ tmp/ coverage/ doc/ ' )
10
+ end
11
+
12
+ task :gem => [:build] do
13
+ shell('gem install pkg/*')
14
+ end
15
+
16
+ task :permissions => [ :clean ] do
17
+ shell("chmod -v o+r,g+r * */* */*/* */*/*/* */*/*/*/* */*/*/*/*/*")
18
+ shell("find . -type d -exec chmod o+x,g+x {} \\;")
19
+ end
20
+
21
+ task :build => :permissions
3
22
 
@@ -1,5 +1,5 @@
1
- require "ventable/version"
2
- require "ventable/event"
1
+ require 'ventable/version'
2
+ require 'ventable/event'
3
3
 
4
4
  module Ventable
5
5
 
@@ -12,7 +12,7 @@ module Ventable
12
12
  end
13
13
 
14
14
  def self.enabled?
15
- @disabled != true
15
+ !@disabled
16
16
  end
17
17
  end
18
18
 
@@ -21,7 +21,7 @@ class String
21
21
  self.gsub(/::/, '/').
22
22
  gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
23
23
  gsub(/([a-z\d])([A-Z])/, '\1_\2').
24
- tr("-", "_").
24
+ tr('-', '_').
25
25
  downcase
26
26
  end
27
27
  end
@@ -20,6 +20,8 @@ module ::Ventable
20
20
  notify_observer_set(self.class.observers) if Ventable.enabled?
21
21
  end
22
22
 
23
+ alias publish fire!
24
+
23
25
  private
24
26
 
25
27
  def notify_observer_set(observer_set)
@@ -28,25 +30,23 @@ module ::Ventable
28
30
  around_block = observer_entry[:around_block]
29
31
  inside_block = -> { notify_observer_set(observer_entry[:observers]) }
30
32
  around_block.call(inside_block)
31
- elsif observer_entry
32
- notify_observer(observer_entry)
33
33
  else
34
- raise Ventable::Error.new("nil in observer_entry set #{observer_set.inspect}!")
34
+ notify_observer(observer_entry)
35
35
  end
36
36
  end
37
37
  end
38
38
 
39
39
  def notify_observer(observer)
40
40
  case observer
41
- when Proc
42
- observer.call(self)
43
- else # class
44
- notify_class_observer(observer)
41
+ when Proc
42
+ observer.call(self)
43
+ else # class
44
+ notify_class_observer(observer)
45
45
  end
46
46
  end
47
47
 
48
48
  def notify_class_observer(observer)
49
- default_handler = self.class.default_callback_method
49
+ default_handler = self.class.send(:default_callback_method)
50
50
  return observer.send(default_handler, self) if observer.respond_to?(default_handler)
51
51
  return observer.send(:handle_event, self) if observer.respond_to?(:handle_event)
52
52
  raise Ventable::Error.new("no suitable event handler method found for #{self.class} in observer #{observer} (try adding #{default_handler} to this observer)")
@@ -57,43 +57,40 @@ module ::Ventable
57
57
  class_eval(&block)
58
58
  end
59
59
 
60
- def notifies(*observer_list, &block)
61
- options = {}
62
- options.merge! observer_list.pop if observer_list.last.is_a?(Hash)
60
+ def notifies(*observer_list, **options, &block)
63
61
  observer_set = self.observers
64
62
  if options[:inside]
65
63
  observer_entry = self.find_observer_group(options[:inside])
66
- if observer_entry.nil?
67
- raise Ventable::Error.new("No group with name #{options[:inside]} found.")
68
- end
64
+ raise Ventable::Error.new("No group with name #{options[:inside]} found.") if observer_entry.nil?
69
65
  observer_set = observer_entry[:observers]
70
66
  end
71
- raise Ventable::Error.new("found nil observer in params #{observer_list.inspect}") if observer_list.any?{|l| l.nil?}
67
+ raise Ventable::Error.new("found nil observer in params #{observer_list.inspect}") if observer_list.any?(&:nil?)
72
68
  observer_list.compact.each { |o| observer_set << o } unless observer_list.empty?
73
69
  observer_set << block if block
74
70
  end
75
71
 
76
72
  def group(name, &block)
77
- g = find_observer_group(name)
78
- raise "Group #{name} already defined by #{g}" if g
79
- self.observers <<
80
- { name: name,
81
- around_block: block,
82
- observers: Set.new
83
- }
73
+ self.observers << { name: name,
74
+ around_block: block,
75
+ observers: Set.new }
76
+
84
77
  end
85
78
 
79
+ protected
80
+
86
81
  def find_observer_group(name)
87
82
  self.observers.find { |o| o.is_a?(Hash) && o[:name] == name }
88
83
  end
89
84
 
85
+ private
86
+
90
87
  # Determine method name to call when notifying observers from this event.
91
88
  def default_callback_method
92
89
  if respond_to?(:ventable_callback_method_name)
93
90
  self.ventable_callback_method_name
94
91
  else
95
92
  target = self
96
- method = "handle_" + target.name.gsub(/::/,'__').underscore.gsub(/_event/, '')
93
+ method = 'handle_' + target.name.gsub(/::/, '__').underscore.gsub(/_event/, '')
97
94
  method.to_sym
98
95
  end
99
96
  end
@@ -1,3 +1,3 @@
1
1
  module Ventable
2
- VERSION = "1.0.0"
2
+ VERSION = '1.2.0'
3
3
  end
@@ -1,17 +1,11 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
1
+ require 'simplecov'
2
+ require 'rspec'
3
+
4
+ SimpleCov.start
7
5
 
8
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9
- require 'rubygems'
10
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
11
6
  require 'ventable'
12
7
 
13
8
  RSpec.configure do |config|
14
- config.treat_symbols_as_metadata_keys_with_true_values = true
15
9
  config.run_all_when_everything_filtered = true
16
10
  config.filter_run :focus
17
11
 
@@ -1,4 +1,4 @@
1
- require 'ventable'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Ventable do
4
4
  before do
@@ -26,13 +26,13 @@ describe Ventable do
26
26
  end
27
27
  end
28
28
 
29
- describe "including Ventable::Event" do
30
- it "should create a class instance variable to keep observers" do
29
+ describe 'including Ventable::Event' do
30
+ it 'should create a class instance variable to keep observers' do
31
31
  expect(TestEvent.observers).not_to be_nil
32
- expect(TestEvent.observers.class.name).to eq("Set")
32
+ expect(TestEvent.observers.class.name).to eq('Set')
33
33
  end
34
34
 
35
- it "should see observers variable from instance methods" do
35
+ it 'should see observers variable from instance methods' do
36
36
  observers = nil
37
37
  TestEvent.new.instance_eval do
38
38
  observers = self.class.observers
@@ -40,7 +40,7 @@ describe Ventable do
40
40
  expect(observers).to_not be_nil
41
41
  end
42
42
 
43
- it "should maintain separate sets of observers for each event" do
43
+ it 'should maintain separate sets of observers for each event' do
44
44
  class AnotherEvent
45
45
  include Ventable::Event
46
46
  end
@@ -48,19 +48,19 @@ describe Ventable do
48
48
  end
49
49
  end
50
50
 
51
- describe "#fire" do
51
+ describe '#fire' do
52
52
  before do
53
53
  class TestEvent
54
54
  include Ventable::Event
55
55
  end
56
56
  end
57
57
 
58
- it "should properly call a Proc observer" do
58
+ it 'should properly call a Proc observer' do
59
59
  run_block = false
60
- event = nil
60
+ event = nil
61
61
  TestEvent.notifies do |e|
62
62
  run_block = true
63
- event = e
63
+ event = e
64
64
  end
65
65
  expect(run_block).to eq(false)
66
66
  expect(event).to be_nil
@@ -72,33 +72,69 @@ describe Ventable do
72
72
  expect(event).not_to be_nil
73
73
  end
74
74
 
75
- it "should properly call a class observer" do
76
- class TestEvent
77
- class << self
78
- attr_accessor :flag
75
+ describe 'class observer' do
76
+ before do
77
+ class TestEvent
78
+ class << self
79
+ attr_accessor :flag
80
+ end
81
+
82
+ self.flag = 'unset'
83
+
84
+ def flag=(value)
85
+ self.class.flag = value
86
+ end
79
87
  end
80
- self.flag = "unset"
81
- def flag= value
82
- self.class.flag = value
88
+
89
+ class TestEventObserver
90
+ def self.handle_test(event)
91
+ event.flag = 'boo'
92
+ end
83
93
  end
84
- end
85
94
 
86
- class TestEventObserver
87
- def self.handle_test event
88
- event.flag = "boo"
95
+ class GlobalObserver
96
+ class << self
97
+ def handle_event(event)
98
+ puts event.inspect
99
+ end
100
+ end
89
101
  end
102
+
103
+ TestEvent.notifies TestEventObserver, GlobalObserver
90
104
  end
91
- TestEvent.notifies TestEventObserver
92
- expect(TestEvent.flag).to eq("unset")
93
105
 
94
- TestEvent.new.fire!
95
- expect(TestEvent.flag).to eq("boo")
106
+ let(:event) { TestEvent.new }
107
+
108
+ before do
109
+ expect(TestEvent.flag).to eq('unset')
110
+ expect(GlobalObserver).to receive(:handle_event).with(event)
111
+ end
112
+
113
+ it 'should set the flag and call observers' do
114
+ event.fire!
115
+ expect(TestEvent.flag).to eq('boo')
116
+ end
117
+
118
+ it 'should also fire via the publish alias' do
119
+ event.publish
120
+ end
121
+
122
+ context 'observer without a handler' do
123
+ before {
124
+ class ObserverWithoutAHandler
125
+ end
126
+ TestEvent.notifies ObserverWithoutAHandler
127
+ }
128
+ it 'should raise an exception' do
129
+ expect { event.publish }.to raise_error(Ventable::Error)
130
+ end
131
+ end
96
132
  end
97
133
 
98
- it "should properly call a group of observers" do
99
- transaction_called = false
134
+ it 'should properly call a group of observers' do
135
+ transaction_called = false
100
136
  transaction_completed = false
101
- transaction = ->(observer_block) {
137
+ transaction = ->(observer_block) {
102
138
  transaction_called = true
103
139
  observer_block.call
104
140
  transaction_completed = true
@@ -110,11 +146,11 @@ describe Ventable do
110
146
  # this flag ensures that this block really runs inside
111
147
  # the transaction group block
112
148
  transaction_already_completed = false
113
- event_inside = nil
149
+ event_inside = nil
114
150
  TestEvent.notifies inside: :transaction do |event|
115
- observer_block_called = true
151
+ observer_block_called = true
116
152
  transaction_already_completed = transaction_completed
117
- event_inside = event
153
+ event_inside = event
118
154
  end
119
155
 
120
156
  expect(transaction_called).to be false
@@ -123,9 +159,9 @@ describe Ventable do
123
159
 
124
160
  TestEvent.new.fire!
125
161
 
126
- expect(transaction_called).to be true
127
- expect(observer_block_called).to be true
128
- expect(transaction_called).to be true
162
+ expect(transaction_called).to be true
163
+ expect(observer_block_called).to be true
164
+ expect(transaction_called).to be true
129
165
  expect(transaction_already_completed).to be false
130
166
  expect(event_inside).to_not be_nil
131
167
  expect(event_inside).to be_a(TestEvent)
@@ -148,7 +184,7 @@ describe Ventable do
148
184
  end
149
185
  end
150
186
 
151
- describe "#default_callback_method" do
187
+ describe '#default_callback_method' do
152
188
  before do
153
189
  class SomeAwesomeEvent
154
190
  include Ventable::Event
@@ -163,6 +199,7 @@ describe Ventable do
163
199
  class SomeOtherStuffHappened
164
200
  include Ventable::Event
165
201
  end
202
+
166
203
  class ClassWithCustomCallbackMethodEvent
167
204
  include Ventable::Event
168
205
 
@@ -172,16 +209,16 @@ describe Ventable do
172
209
  end
173
210
  end
174
211
 
175
- it "should properly set the callback method name" do
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)
212
+ it 'should properly set the callback method name' do
213
+ expect(SomeAwesomeEvent.send(:default_callback_method)).to eq(:handle_some_awesome)
214
+ expect(Blah::AnotherSweetEvent.send(:default_callback_method)).to eq(:handle_blah__another_sweet)
215
+ expect(SomeOtherStuffHappened.send(:default_callback_method)).to eq(:handle_some_other_stuff_happened)
216
+ expect(ClassWithCustomCallbackMethodEvent.send(:default_callback_method)).to eq(:handle_my_special_event)
180
217
  end
181
218
  end
182
219
 
183
- describe "#configure" do
184
- it "properly configures the event with observers" do
220
+ describe '#configure' do
221
+ it 'properly configures the event with observers' do
185
222
  notified_observer = false
186
223
  TestEvent.configure do
187
224
  notifies do
@@ -192,11 +229,11 @@ describe Ventable do
192
229
  expect(notified_observer).to be true
193
230
  end
194
231
 
195
- it "configures observers with groups" do
196
- notified_observer = false
232
+ it 'configures observers with groups' do
233
+ notified_observer = false
197
234
  called_transaction = false
198
235
  TestEvent.configure do
199
- group :transaction, &->(b){
236
+ group :transaction, &->(b) {
200
237
  b.call
201
238
  called_transaction = true
202
239
  }
@@ -209,24 +246,24 @@ describe Ventable do
209
246
  expect(called_transaction).to be true
210
247
  end
211
248
 
212
- it "throws exception if :inside references unknown group" do
249
+ it 'throws exception if :inside references unknown group' do
213
250
  begin
214
251
  TestEvent.configure do
215
252
  notifies inside: :transaction do
216
253
  # some stuff
217
254
  end
218
255
  end
219
- fail "Shouldn't reach here, must throw a valid exception"
256
+ fail 'Shouldn\'t reach here, must throw a valid exception'
220
257
  rescue Exception => e
221
258
  expect(e.class).to eq(Ventable::Error)
222
259
  end
223
260
  end
224
- it "throws exception if nil observer added to the list" do
261
+ it 'throws exception if nil observer added to the list' do
225
262
  begin
226
263
  TestEvent.configure do
227
264
  notifies nil
228
265
  end
229
- fail "Shouldn't reach here, must throw a valid exception"
266
+ fail 'Shouldn\'t reach here, must throw a valid exception'
230
267
  rescue Exception => e
231
268
  expect(e.class).to eq(Ventable::Error)
232
269
  end
@@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.version = Ventable::VERSION
18
18
 
19
19
  gem.add_development_dependency "rake"
20
+ gem.add_development_dependency "simplecov"
20
21
  gem.add_development_dependency "rspec"
21
22
  gem.add_development_dependency "rspec-mocks"
22
23
  gem.add_development_dependency 'guard-rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ventable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.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: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2019-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simplecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -78,7 +92,6 @@ files:
78
92
  - ".rspec"
79
93
  - ".travis.yml"
80
94
  - Gemfile
81
- - Gemfile.lock
82
95
  - Guardfile
83
96
  - LICENSE
84
97
  - README.md
@@ -108,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
121
  version: '0'
109
122
  requirements: []
110
123
  rubyforge_project:
111
- rubygems_version: 2.5.1
124
+ rubygems_version: 2.7.7
112
125
  signing_key:
113
126
  specification_version: 4
114
127
  summary: Event/Observable design pattern in ruby
@@ -1,72 +0,0 @@
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