ventable 1.2.0 → 1.3.1

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
2
  SHA256:
3
- metadata.gz: 57b42bb96d2c3c0bac1f4fc8e97ed42b3ee5eb9494a9f36f04cea0c0888765e3
4
- data.tar.gz: 13b3f1b9860d9b26b812bf0ff6b2daa4d318af0906d71d4e02a17577067e7eca
3
+ metadata.gz: 6f8a7adee18ece871971236ea00ee70c35c278259fed5cd499c1f3c8d5e097d0
4
+ data.tar.gz: 4e4137f676a3374e17377db94ede9c59d232358f9bc82e3fbbbf90b817bbe514
5
5
  SHA512:
6
- metadata.gz: 2a032511c88f1f9f2f62f2a0b3b39a2f81337585550596634eabb875c34731bfe458477a4246e47e2624363041fccb92fc6e98b7628d5e4bb32a6a62ab058511
7
- data.tar.gz: 396af327f6e393cc9db4efd5f12c2787eeec7fa2cb1f83f9c600e389bd8296bb3092713a5e9056b252acd9e1129e5703853e0099cc82f9a58646c0bc5b1532a0
6
+ metadata.gz: 85a2ae18e873826a4ac34790d99ac5ed4f65e9ab2995e71edcf14b7cd78f86507df842c3c78ecafaae8df21e533e4c0fa39f765429ec9992056a776caf7fd4df
7
+ data.tar.gz: fa01a1e9de8962f299fa332ac542d34389eb853a9ddce5047dd85fbf5897e377a139ac6f598fe2112e9ba20361a8ca5564238ec9c940a203812dbe8d7ad6a806
@@ -0,0 +1,36 @@
1
+ name: Rubocop
2
+
3
+ on:
4
+ push:
5
+ branches: [ "main" ]
6
+ pull_request:
7
+ branches: [ "main" ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Rubocop
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ packages: write
16
+
17
+ strategy:
18
+ matrix:
19
+ ruby-version: ['2.7', '3.0', '3.1', '3.2']
20
+
21
+ steps:
22
+ - uses: actions/checkout@v3
23
+ - name: Set up Ruby ${{ matrix.ruby-version }}
24
+ uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby-version }}
27
+
28
+ - name: Bundle Install
29
+ run: |
30
+ bundle check || bundle install -j 5
31
+
32
+ - name: Rubocop
33
+ run: |
34
+ bundle exec rubocop
35
+
36
+
@@ -0,0 +1,34 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+ name: RSpec
8
+
9
+ on:
10
+ push:
11
+ branches: [ "main" ]
12
+ pull_request:
13
+ branches: [ "main" ]
14
+
15
+ jobs:
16
+ test:
17
+ runs-on: ubuntu-latest
18
+ strategy:
19
+ matrix:
20
+ ruby-version: ['2.7', '3.0', '3.1', '3.2']
21
+
22
+ steps:
23
+ - uses: actions/checkout@v3
24
+ - name: Set up Ruby
25
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
26
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby-version }}
30
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
31
+ - name: bundle
32
+ run: bundle check || bundle install -j 4
33
+ - name: RSpecs
34
+ run: bundle exec rspec --format documentation
data/.gitignore CHANGED
@@ -18,3 +18,5 @@ test/version_tmp
18
18
  tmp
19
19
  .idea/
20
20
  vendor/
21
+ .rubocop/cache
22
+ .rubocop-*
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ inherit_from:
2
+ - .rubocop_todo.yml
3
+ - https://relaxed.ruby.style/rubocop.yml
4
+
5
+ inherit_mode:
6
+ merge:
7
+ - Exclude
8
+
9
+ require:
10
+ - rubocop-rspec
11
+ - rubocop-rake
12
+
13
+ AllCops:
14
+ TargetRubyVersion: '2.7'
15
+ UseCache: true
16
+ CacheRootDirectory: ./.rubocop/cache
17
+ NewCops: enable
18
+ Exclude:
19
+ - 'bin/*'
20
+ - 'vendor/*'
21
+
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,82 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2023-08-28 17:02:07 UTC using RuboCop version 1.56.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: Severity, Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'ventable.gemspec'
15
+
16
+ # Offense count: 11
17
+ # Configuration parameters: AllowedMethods.
18
+ # AllowedMethods: enums
19
+ Lint/ConstantDefinitionInBlock:
20
+ Exclude:
21
+ - 'spec/ventable/ventable_spec.rb'
22
+
23
+ # Offense count: 1
24
+ # Configuration parameters: AllowComments.
25
+ Lint/EmptyClass:
26
+ Exclude:
27
+ - 'spec/ventable/ventable_spec.rb'
28
+
29
+ # Offense count: 2
30
+ Lint/RescueException:
31
+ Exclude:
32
+ - 'spec/ventable/ventable_spec.rb'
33
+
34
+ # Offense count: 1
35
+ # Configuration parameters: Prefixes, AllowedPatterns.
36
+ # Prefixes: when, with, without
37
+ RSpec/ContextWording:
38
+ Exclude:
39
+ - 'spec/ventable/ventable_spec.rb'
40
+
41
+ # Offense count: 7
42
+ # Configuration parameters: CountAsOne.
43
+ RSpec/ExampleLength:
44
+ Max: 26
45
+
46
+ # Offense count: 2
47
+ RSpec/ExpectInHook:
48
+ Exclude:
49
+ - 'spec/ventable/ventable_spec.rb'
50
+
51
+ # Offense count: 12
52
+ RSpec/LeakyConstantDeclaration:
53
+ Exclude:
54
+ - 'spec/ventable/ventable_spec.rb'
55
+
56
+ # Offense count: 1
57
+ # Configuration parameters: .
58
+ # SupportedStyles: have_received, receive
59
+ RSpec/MessageSpies:
60
+ EnforcedStyle: receive
61
+
62
+ # Offense count: 5
63
+ RSpec/MultipleExpectations:
64
+ Max: 9
65
+
66
+ # Offense count: 1
67
+ # Configuration parameters: AllowedGroups.
68
+ RSpec/NestedGroups:
69
+ Max: 4
70
+
71
+ # Offense count: 1
72
+ # Configuration parameters: AllowedPatterns.
73
+ # AllowedPatterns: ^expect_, ^assert_
74
+ RSpec/NoExpectationExample:
75
+ Exclude:
76
+ - 'spec/ventable/ventable_spec.rb'
77
+
78
+ # Offense count: 2
79
+ # This cop supports safe autocorrection (--autocorrect).
80
+ Rake/Desc:
81
+ Exclude:
82
+ - 'Rakefile'
data/Gemfile CHANGED
@@ -1,2 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
  gemspec
5
+
6
+ gem 'guard-rspec'
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "rspec-its"
10
+ gem "rspec-mocks"
11
+ gem "rubocop"
12
+ gem "rubocop-rake"
13
+ gem "rubocop-rspec"
14
+ gem "simplecov"
data/Guardfile CHANGED
@@ -1,15 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
- #^syntax detection
2
+ # frozen_string_literal: true
3
+
4
+ # ^syntax detection
3
5
 
4
6
  # A sample Guardfile
5
7
  # More info at https://github.com/guard/guard#readme
6
8
 
7
9
  guard 'rspec' do
8
- watch(%r{^ventable\.gemspec}) { "spec"}
10
+ watch(/^ventable\.gemspec/) { "spec" }
9
11
  watch(%r{^lib/(.+)\.rb$}) { "spec" }
10
12
 
11
13
  watch(%r{^spec/.+_spec\.rb$})
12
- watch('spec/spec_helper.rb') { "spec" }
14
+ watch('spec/spec_helper.rb') { "spec" }
13
15
  watch(%r{spec/support/.*}) { "spec" }
14
16
  end
15
-
data/README.md CHANGED
@@ -1,14 +1,11 @@
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)
1
+ ![Gem Version](https://badge.fury.io/rb/ventable.svg)
6
2
  [![Gitter](https://img.shields.io/gitter/room/gitterHQ/gitter.svg)](https://gitter.im/kigster/ventable)
3
+ ![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkigster%2Fventable.svg?type=shield)
7
4
 
8
- [![Test Coverage](https://api.codeclimate.com/v1/badges/c28d141c978293886d21/test_coverage)](https://codeclimate.com/github/kigster/ventable/test_coverage)
9
-
5
+ [![RSpec](https://github.com/kigster/ventable/actions/workflows/ruby.yml/badge.svg)](https://github.com/kigster/ventable/actions/workflows/ruby.yml)
6
+ [![Rubocop](https://github.com/kigster/ventable/actions/workflows/rubocop.yml/badge.svg)](https://github.com/kigster/ventable/actions/workflows/rubocop.yml)
10
7
 
11
- # Ventable
8
+ # Ventable — Observable Pattern On Steroids
12
9
 
13
10
  This gem is a variation of the [Observer Design Pattern](https://en.wikipedia.org/wiki/Observer_pattern).
14
11
 
@@ -35,10 +32,10 @@ Ventable has several plugins that add various functionality on top of the basic
35
32
  This gem has been verified to work in the following ruby versions:
36
33
 
37
34
  * MRI Ruby
38
- * 1.9.3-p551
39
- * 2.2
40
- * 2.3
41
- * 2.4
35
+ * 3.2
36
+ * 3.1
37
+ * 3.0
38
+ * 2.7
42
39
 
43
40
  The gem also likely works with non-MRI rubies, but it has not been tested.
44
41
 
@@ -233,3 +230,7 @@ For more information, check out the following blog post:
233
230
  ## Author
234
231
 
235
232
  Konstantin Gredeskoul, @kig, http://github.com/kigster
233
+
234
+
235
+ ## License
236
+ [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkigster%2Fventable.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkigster%2Fventable?ref=badge_large)
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
5
  def shell(*args)
@@ -9,14 +11,13 @@ task :clean do
9
11
  shell('rm -rf pkg/ tmp/ coverage/ doc/ ' )
10
12
  end
11
13
 
12
- task :gem => [:build] do
14
+ task gem: [:build] do
13
15
  shell('gem install pkg/*')
14
16
  end
15
17
 
16
- task :permissions => [ :clean ] do
18
+ task permissions: [:clean] do
17
19
  shell("chmod -v o+r,g+r * */* */*/* */*/*/* */*/*/*/* */*/*/*/*/*")
18
20
  shell("find . -type d -exec chmod o+x,g+x {} \\;")
19
21
  end
20
22
 
21
- task :build => :permissions
22
-
23
+ task build: :permissions
@@ -1,19 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
4
+ require 'active_support/inflector'
2
5
 
3
6
  module ::Ventable
4
7
  class Error < RuntimeError
5
8
  end
6
9
 
7
10
  module Event
8
- def self.included(klazz)
9
- klazz.instance_eval do
11
+ def self.included(klass)
12
+ klass.instance_eval do
10
13
  @observers = Set.new
11
14
  class << self
12
15
  attr_accessor :observers
13
16
  end
14
17
  end
15
18
 
16
- klazz.extend ClassMethods
19
+ klass.extend ClassMethods
17
20
  end
18
21
 
19
22
  def fire!
@@ -28,8 +31,7 @@ module ::Ventable
28
31
  observer_set.each do |observer_entry|
29
32
  if observer_entry.is_a?(Hash)
30
33
  around_block = observer_entry[:around_block]
31
- inside_block = -> { notify_observer_set(observer_entry[:observers]) }
32
- around_block.call(inside_block)
34
+ around_block&.call(-> { notify_observer_set(observer_entry[:observers]) })
33
35
  else
34
36
  notify_observer(observer_entry)
35
37
  end
@@ -49,7 +51,8 @@ module ::Ventable
49
51
  default_handler = self.class.send(:default_callback_method)
50
52
  return observer.send(default_handler, self) if observer.respond_to?(default_handler)
51
53
  return observer.send(:handle_event, self) if observer.respond_to?(:handle_event)
52
- raise Ventable::Error.new("no suitable event handler method found for #{self.class} in observer #{observer} (try adding #{default_handler} to this observer)")
54
+
55
+ raise Ventable::Error, "no suitable event handler method found for #{self.class} in observer #{observer} (try adding #{default_handler} to this observer)"
53
56
  end
54
57
 
55
58
  module ClassMethods
@@ -58,28 +61,29 @@ module ::Ventable
58
61
  end
59
62
 
60
63
  def notifies(*observer_list, **options, &block)
61
- observer_set = self.observers
64
+ observer_set = observers
62
65
  if options[:inside]
63
- observer_entry = self.find_observer_group(options[:inside])
64
- raise Ventable::Error.new("No group with name #{options[:inside]} found.") if observer_entry.nil?
66
+ observer_entry = find_observer_group(options[:inside])
67
+ raise Ventable::Error, "No group with name #{options[:inside]} found." if observer_entry.nil?
68
+
65
69
  observer_set = observer_entry[:observers]
66
70
  end
67
- raise Ventable::Error.new("found nil observer in params #{observer_list.inspect}") if observer_list.any?(&:nil?)
71
+ raise Ventable::Error, "found nil observer in params #{observer_list.inspect}" if observer_list.any?(&:nil?)
72
+
68
73
  observer_list.compact.each { |o| observer_set << o } unless observer_list.empty?
69
74
  observer_set << block if block
70
75
  end
71
76
 
72
77
  def group(name, &block)
73
- self.observers << { name: name,
74
- around_block: block,
75
- observers: Set.new }
76
-
78
+ observers << { name: name,
79
+ around_block: block,
80
+ observers: Set.new }
77
81
  end
78
82
 
79
83
  protected
80
84
 
81
85
  def find_observer_group(name)
82
- self.observers.find { |o| o.is_a?(Hash) && o[:name] == name }
86
+ observers.find { |o| o.is_a?(Hash) && o[:name] == name }
83
87
  end
84
88
 
85
89
  private
@@ -87,10 +91,14 @@ module ::Ventable
87
91
  # Determine method name to call when notifying observers from this event.
88
92
  def default_callback_method
89
93
  if respond_to?(:ventable_callback_method_name)
90
- self.ventable_callback_method_name
94
+ ventable_callback_method_name
91
95
  else
92
96
  target = self
93
- method = 'handle_' + target.name.gsub(/::/, '__').underscore.gsub(/_event/, '')
97
+
98
+ method = "handle_#{ActiveSupport::Inflector.underscore(target.name)}".
99
+ gsub(%r{/([^/]*)}, '__\1').
100
+ gsub(/_event$/, '')
101
+
94
102
  method.to_sym
95
103
  end
96
104
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Ventable
2
- VERSION = '1.2.0'
4
+ VERSION = '1.3.1'
3
5
  end
data/lib/ventable.rb CHANGED
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ventable/version'
2
4
  require 'ventable/event'
3
5
 
4
6
  module Ventable
5
-
6
7
  def self.disable
7
8
  @disabled = true
8
9
  end
@@ -18,10 +19,10 @@ end
18
19
 
19
20
  class String
20
21
  def underscore
21
- self.gsub(/::/, '/').
22
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
23
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
24
- tr('-', '_').
25
- downcase
22
+ gsub("::", '/').
23
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
24
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
25
+ tr('-', '_').
26
+ downcase
26
27
  end
27
28
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
4
  require 'rspec'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Ventable do
@@ -8,43 +10,44 @@ describe Ventable do
8
10
  end
9
11
 
10
12
  describe '::enabled?' do
11
- after { Ventable.enable }
13
+ after { described_class.enable }
12
14
 
13
15
  it 'is true by default' do
14
- expect(Ventable.enabled?).to be true
16
+ expect(described_class.enabled?).to be true
15
17
  end
16
18
 
17
19
  it 'is false after Ventable is disabled' do
18
- Ventable.disable
19
- expect(Ventable.enabled?).to be false
20
+ described_class.disable
21
+ expect(described_class.enabled?).to be false
20
22
  end
21
23
 
22
24
  it 'is true after Ventable is re-enabled' do
23
- Ventable.disable
24
- Ventable.enable
25
- expect(Ventable.enabled?).to be true
25
+ described_class.disable
26
+ described_class.enable
27
+ expect(described_class.enabled?).to be true
26
28
  end
27
29
  end
28
30
 
29
31
  describe 'including Ventable::Event' do
30
- it 'should create a class instance variable to keep observers' do
32
+ it 'creates a class instance variable to keep observers' do
31
33
  expect(TestEvent.observers).not_to be_nil
32
34
  expect(TestEvent.observers.class.name).to eq('Set')
33
35
  end
34
36
 
35
- it 'should see observers variable from instance methods' do
37
+ it 'sees observers variable from instance methods' do
36
38
  observers = nil
37
39
  TestEvent.new.instance_eval do
38
40
  observers = self.class.observers
39
41
  end
40
- expect(observers).to_not be_nil
42
+ expect(observers).not_to be_nil
41
43
  end
42
44
 
43
- it 'should maintain separate sets of observers for each event' do
45
+ it 'maintains separate sets of observers for each event' do
44
46
  class AnotherEvent
45
47
  include Ventable::Event
46
48
  end
47
- expect(AnotherEvent.observers.object_id).to_not eq(TestEvent.observers.object_id)
49
+
50
+ expect(AnotherEvent.observers.object_id).not_to eq(TestEvent.observers.object_id)
48
51
  end
49
52
  end
50
53
 
@@ -55,14 +58,14 @@ describe Ventable do
55
58
  end
56
59
  end
57
60
 
58
- it 'should properly call a Proc observer' do
61
+ it 'properly call a Proc observer' do
59
62
  run_block = false
60
- event = nil
63
+ event = nil
61
64
  TestEvent.notifies do |e|
62
65
  run_block = true
63
- event = e
66
+ event = e
64
67
  end
65
- expect(run_block).to eq(false)
68
+ expect(run_block).to be(false)
66
69
  expect(event).to be_nil
67
70
 
68
71
  # fire the event
@@ -101,21 +104,18 @@ describe Ventable do
101
104
  end
102
105
 
103
106
  TestEvent.notifies TestEventObserver, GlobalObserver
104
- end
105
-
106
- let(:event) { TestEvent.new }
107
-
108
- before do
109
107
  expect(TestEvent.flag).to eq('unset')
110
108
  expect(GlobalObserver).to receive(:handle_event).with(event)
111
109
  end
112
110
 
113
- it 'should set the flag and call observers' do
111
+ let(:event) { TestEvent.new }
112
+
113
+ it 'sets the flag and call observers' do
114
114
  event.fire!
115
115
  expect(TestEvent.flag).to eq('boo')
116
116
  end
117
117
 
118
- it 'should also fire via the publish alias' do
118
+ it 'also fire via the publish alias' do
119
119
  event.publish
120
120
  end
121
121
 
@@ -123,18 +123,20 @@ describe Ventable do
123
123
  before {
124
124
  class ObserverWithoutAHandler
125
125
  end
126
+
126
127
  TestEvent.notifies ObserverWithoutAHandler
127
128
  }
128
- it 'should raise an exception' do
129
+
130
+ it 'raises an exception' do
129
131
  expect { event.publish }.to raise_error(Ventable::Error)
130
132
  end
131
133
  end
132
134
  end
133
135
 
134
- it 'should properly call a group of observers' do
135
- transaction_called = false
136
+ it 'properly call a group of observers' do
137
+ transaction_called = false
136
138
  transaction_completed = false
137
- transaction = ->(observer_block) {
139
+ transaction = ->(observer_block) {
138
140
  transaction_called = true
139
141
  observer_block.call
140
142
  transaction_completed = true
@@ -146,11 +148,11 @@ describe Ventable do
146
148
  # this flag ensures that this block really runs inside
147
149
  # the transaction group block
148
150
  transaction_already_completed = false
149
- event_inside = nil
151
+ event_inside = nil
150
152
  TestEvent.notifies inside: :transaction do |event|
151
- observer_block_called = true
153
+ observer_block_called = true
152
154
  transaction_already_completed = transaction_completed
153
- event_inside = event
155
+ event_inside = event
154
156
  end
155
157
 
156
158
  expect(transaction_called).to be false
@@ -163,18 +165,18 @@ describe Ventable do
163
165
  expect(observer_block_called).to be true
164
166
  expect(transaction_called).to be true
165
167
  expect(transaction_already_completed).to be false
166
- expect(event_inside).to_not be_nil
168
+ expect(event_inside).not_to be_nil
167
169
  expect(event_inside).to be_a(TestEvent)
168
170
  end
169
171
 
170
172
  context 'when globally disabled' do
171
- before { Ventable.disable }
172
- after { Ventable.enable }
173
+ before { described_class.disable }
174
+ after { described_class.enable }
173
175
 
174
176
  it 'does not notify observers' do
175
177
  observers_notified = false
176
178
 
177
- TestEvent.notifies do |event|
179
+ TestEvent.notifies do |_event|
178
180
  observers_notified = true
179
181
  end
180
182
 
@@ -196,10 +198,6 @@ describe Ventable do
196
198
  end
197
199
  end
198
200
 
199
- class SomeOtherStuffHappened
200
- include Ventable::Event
201
- end
202
-
203
201
  class ClassWithCustomCallbackMethodEvent
204
202
  include Ventable::Event
205
203
 
@@ -207,14 +205,31 @@ describe Ventable do
207
205
  :handle_my_special_event
208
206
  end
209
207
  end
208
+
209
+ module Blah
210
+ module Foo
211
+ class BarClosedEvent
212
+ include Ventable::Event
213
+ end
214
+ end
215
+ end
210
216
  end
211
217
 
212
- it 'should properly set the callback method name' do
218
+ it 'properly sets the callback method on a Module-less class' do
213
219
  expect(SomeAwesomeEvent.send(:default_callback_method)).to eq(:handle_some_awesome)
220
+ end
221
+
222
+ it 'properly sets the callback method on a Class within a Module' do
214
223
  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)
224
+ end
225
+
226
+ it 'properly sets the callback method on a class with a custom default method handler name' do
216
227
  expect(ClassWithCustomCallbackMethodEvent.send(:default_callback_method)).to eq(:handle_my_special_event)
217
228
  end
229
+
230
+ it 'properly sets the callback method on a class within a nested module' do
231
+ expect(Blah::Foo::BarClosedEvent.send(:default_callback_method)).to eq(:handle_blah__foo__bar_closed)
232
+ end
218
233
  end
219
234
 
220
235
  describe '#configure' do
@@ -230,7 +245,7 @@ describe Ventable do
230
245
  end
231
246
 
232
247
  it 'configures observers with groups' do
233
- notified_observer = false
248
+ notified_observer = false
234
249
  called_transaction = false
235
250
  TestEvent.configure do
236
251
  group :transaction, &->(b) {
@@ -247,26 +262,23 @@ describe Ventable do
247
262
  end
248
263
 
249
264
  it 'throws exception if :inside references unknown group' do
250
- begin
251
- TestEvent.configure do
252
- notifies inside: :transaction do
253
- # some stuff
254
- end
265
+ TestEvent.configure do
266
+ notifies inside: :transaction do
267
+ # some stuff
255
268
  end
256
- fail 'Shouldn\'t reach here, must throw a valid exception'
257
- rescue Exception => e
258
- expect(e.class).to eq(Ventable::Error)
259
269
  end
270
+ fail 'Shouldn\'t reach here, must throw a valid exception'
271
+ rescue Exception => e
272
+ expect(e.class).to eq(Ventable::Error)
260
273
  end
274
+
261
275
  it 'throws exception if nil observer added to the list' do
262
- begin
263
- TestEvent.configure do
264
- notifies nil
265
- end
266
- fail 'Shouldn\'t reach here, must throw a valid exception'
267
- rescue Exception => e
268
- expect(e.class).to eq(Ventable::Error)
276
+ TestEvent.configure do
277
+ notifies nil
269
278
  end
279
+ fail 'Shouldn\'t reach here, must throw a valid exception'
280
+ rescue Exception => e
281
+ expect(e.class).to eq(Ventable::Error)
270
282
  end
271
283
  end
272
284
  end
data/ventable.gemspec CHANGED
@@ -1,24 +1,21 @@
1
+ # frozen_string_literal: true
1
2
 
2
- # -*- encoding: utf-8 -*-
3
- require File.expand_path('../lib/ventable/version', __FILE__)
3
+ require File.expand_path('lib/ventable/version', __dir__)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.authors = ["Konstantin Gredeskoul"]
7
7
  gem.email = ["kigster@gmail.com"]
8
- gem.description = %q{Event/Observable design pattern in ruby}
9
- gem.summary = %q{Event/Observable design pattern in ruby}
8
+ gem.description = 'Event/Observable design pattern in ruby'
9
+ gem.summary = 'Event/Observable design pattern in ruby'
10
10
  gem.homepage = "https://github.com/kigster/ventable"
11
11
 
12
12
  gem.files = `git ls-files`.split($\)
13
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
14
  gem.name = "ventable"
16
15
  gem.require_paths = ["lib"]
17
16
  gem.version = Ventable::VERSION
18
17
 
19
- gem.add_development_dependency "rake"
20
- gem.add_development_dependency "simplecov"
21
- gem.add_development_dependency "rspec"
22
- gem.add_development_dependency "rspec-mocks"
23
- gem.add_development_dependency 'guard-rspec'
18
+ gem.metadata['rubygems_mfa_required'] = 'true'
19
+
20
+ gem.add_runtime_dependency 'activesupport', '>= 5'
24
21
  end
metadata CHANGED
@@ -1,85 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ventable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Gredeskoul
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-08 00:00:00.000000000 Z
11
+ date: 2024-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
19
+ version: '5'
20
+ type: :runtime
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: '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'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec-mocks
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard-rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
26
+ version: '5'
83
27
  description: Event/Observable design pattern in ruby
84
28
  email:
85
29
  - kigster@gmail.com
@@ -88,9 +32,12 @@ extensions: []
88
32
  extra_rdoc_files: []
89
33
  files:
90
34
  - ".atom-build.json"
35
+ - ".github/workflows/rubocop.yml"
36
+ - ".github/workflows/ruby.yml"
91
37
  - ".gitignore"
92
38
  - ".rspec"
93
- - ".travis.yml"
39
+ - ".rubocop.yml"
40
+ - ".rubocop_todo.yml"
94
41
  - Gemfile
95
42
  - Guardfile
96
43
  - LICENSE
@@ -104,8 +51,9 @@ files:
104
51
  - ventable.gemspec
105
52
  homepage: https://github.com/kigster/ventable
106
53
  licenses: []
107
- metadata: {}
108
- post_install_message:
54
+ metadata:
55
+ rubygems_mfa_required: 'true'
56
+ post_install_message:
109
57
  rdoc_options: []
110
58
  require_paths:
111
59
  - lib
@@ -120,11 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
68
  - !ruby/object:Gem::Version
121
69
  version: '0'
122
70
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.7.7
125
- signing_key:
71
+ rubygems_version: 3.5.6
72
+ signing_key:
126
73
  specification_version: 4
127
74
  summary: Event/Observable design pattern in ruby
128
- test_files:
129
- - spec/spec_helper.rb
130
- - spec/ventable/ventable_spec.rb
75
+ test_files: []
data/.travis.yml DELETED
@@ -1,18 +0,0 @@
1
- language: ruby
2
- rvm:
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"