signal 0.3.0 → 1.0.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
2
  SHA1:
3
- metadata.gz: f93acc02fac0dc15d821540be7b8429a1c4ee767
4
- data.tar.gz: ccbf61c85f7448b07f32e5a708905862b63a66f3
3
+ metadata.gz: 0da1e84da778b581b1e7b325a1437ecc720f56ca
4
+ data.tar.gz: d1356905f81403f12aac8bebc3205ffb1c031f74
5
5
  SHA512:
6
- metadata.gz: edebdf9690ad027d27f25a1e80d94272750b1a62434df184d6894c7a253b0f050fe06dda337601179886d22b02d4bffeb5155e695a8d7d09b27f88aef4f3d1f6
7
- data.tar.gz: 055b3b383611a0de961f0f66d4cfd7b0b40fcfc36dd252e46d2cdade60dd34b9f73ce50bd07a4e677e596063c3154dbb96687ac788236d4cad9e06a6a15526ac
6
+ metadata.gz: 1dd9dc2736009aefe24b4aa0dea8d4febd50a3ab9c6b0a8b5eadb95c15e513007c8fedb0bf332809e229e38a0606059b9a8f2a44507f74a47bfabfcb788fbac1
7
+ data.tar.gz: 292aa7515e1e260860a298da7680235e5418462301042d260d44bc23b0016619eeec6654cc5c045a2ce2527b17b13a1dec9d6808b6f1c2fa67d889c7646057ce
data/.travis.yml CHANGED
@@ -5,7 +5,6 @@ script: bundle exec rspec
5
5
  rvm:
6
6
  - '2.2'
7
7
  - '2.1'
8
- - '2.0'
9
8
  addons:
10
9
  code_climate:
11
10
  repo_token:
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Signal
2
+
3
+ ### v1.0.0
4
+
5
+ - Use `include Signal.active_record` instead of `include Signal::ActiveRecord`. This fixes problems with [constant lookup](https://github.com/fnando/signal/issues/2).
data/README.md CHANGED
@@ -123,7 +123,7 @@ You can use Signal with ActiveRecord, which will give you some default events li
123
123
 
124
124
  ```ruby
125
125
  class Thing < ActiveRecord::Base
126
- include Signal::ActiveRecord
126
+ include Signal.active_record
127
127
 
128
128
  validates_presence_of :name
129
129
  end
@@ -197,7 +197,7 @@ end
197
197
 
198
198
  ### Signal::Call
199
199
 
200
- You can include `Signal::Call` instead, so you can have a common interface for your observable object. This will add the `.call()` method to the target class, which will delegate attributes to the observable's `initialize` method and call its `call` method.
200
+ You can include `Signal.call` instead, so you can have a common interface for your observable object. This will add the `.call()` method to the target class, which will delegate attributes to the observable's `initialize` method and call its `call` method.
201
201
 
202
202
  ```ruby
203
203
  class Contact
data/lib/signal.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'signal/active_record'
2
- require 'signal/listener'
3
- require 'signal/call'
4
1
  require 'signal/version'
2
+ require 'signal/listener'
3
+ require 'signal/extensions/active_record'
4
+ require 'signal/extensions/call'
5
5
 
6
6
  module Signal
7
7
  def on(event, &block)
@@ -1,19 +1,22 @@
1
1
  module Signal
2
- module ActiveRecord
3
- def self.included(base)
4
- base.class_eval do
5
- include Signal
6
- include InstanceMethods
7
-
8
- around_create :around_create_signal
9
- around_save :around_save_signal
10
- around_destroy :around_destroy_signal
11
- before_validation :before_validation_signal
12
- after_validation :after_validation_signal
2
+ def self.active_record
3
+ Extensions::ActiveRecord
4
+ end
5
+
6
+ module Extensions
7
+ module ActiveRecord
8
+ def self.included(base)
9
+ base.class_eval do
10
+ include Signal
11
+
12
+ around_create :around_create_signal
13
+ around_save :around_save_signal
14
+ around_destroy :around_destroy_signal
15
+ before_validation :before_validation_signal
16
+ after_validation :after_validation_signal
17
+ end
13
18
  end
14
- end
15
19
 
16
- module InstanceMethods
17
20
  private
18
21
  def around_create_signal
19
22
  emit_signal(:before, :create, self)
@@ -0,0 +1,23 @@
1
+ module Signal
2
+ def self.call
3
+ Extensions::Call
4
+ end
5
+
6
+ module Extensions
7
+ module Call
8
+ def self.included(target)
9
+ target.include(Signal)
10
+ target.extend(ClassMethods)
11
+ end
12
+
13
+ module ClassMethods
14
+ def call(*args, &block)
15
+ new(*args).tap do |instance|
16
+ yield(instance)
17
+ instance.call
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Signal
2
- VERSION = '0.3.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Signal::ActiveRecord do
3
+ describe Signal::Extensions::ActiveRecord do
4
4
  let(:callable) { Callable.new }
5
5
  let(:user) { User.new(:username => 'johndoe') }
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Signal::Call do
3
+ describe Signal::Extensions::Call do
4
4
  let(:callable) { Callable.new }
5
5
 
6
6
  it 'initializes observable with arguments' do
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Constant lookup', 'https://github.com/fnando/signal/issues/2' do
4
+ let(:callable) { Callable.new }
5
+
6
+ it 'triggers event' do
7
+ emitter = Emitter.new
8
+ emitter.on(:success, &callable)
9
+ expect(callable).to receive(:called).with(no_args)
10
+
11
+ emitter.call
12
+ end
13
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,7 @@ require 'support/observable'
11
11
  require 'support/observable_with_call'
12
12
  require 'support/callable'
13
13
  require 'support/user'
14
+ require 'support/emitter'
14
15
 
15
16
  ActiveRecord::Base.establish_connection({
16
17
  :adapter => 'sqlite3',
@@ -0,0 +1,9 @@
1
+ class Emitter
2
+ include Signal
3
+
4
+ def call
5
+ ActiveRecord::Base.transaction do
6
+ emit(:success)
7
+ end
8
+ end
9
+ end
data/spec/support/user.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  class User < ActiveRecord::Base
2
- include Signal::ActiveRecord
2
+ include Signal.active_record
3
3
  validates_presence_of :username
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: signal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-24 00:00:00.000000000 Z
11
+ date: 2015-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -77,6 +77,7 @@ files:
77
77
  - ".gitignore"
78
78
  - ".rspec"
79
79
  - ".travis.yml"
80
+ - CHANGELOG.md
80
81
  - Gemfile
81
82
  - LICENSE.txt
82
83
  - README.md
@@ -88,17 +89,19 @@ files:
88
89
  - examples/chain.rb
89
90
  - examples/listener.rb
90
91
  - lib/signal.rb
91
- - lib/signal/active_record.rb
92
- - lib/signal/call.rb
92
+ - lib/signal/extensions/active_record.rb
93
+ - lib/signal/extensions/call.rb
93
94
  - lib/signal/listener.rb
94
95
  - lib/signal/version.rb
95
96
  - signal.gemspec
96
97
  - spec/signal/activerecord_spec.rb
97
98
  - spec/signal/call_spec.rb
99
+ - spec/signal/issues/2_spec.rb
98
100
  - spec/signal/listener_spec.rb
99
101
  - spec/signal/signal_spec.rb
100
102
  - spec/spec_helper.rb
101
103
  - spec/support/callable.rb
104
+ - spec/support/emitter.rb
102
105
  - spec/support/observable.rb
103
106
  - spec/support/observable_with_call.rb
104
107
  - spec/support/user.rb
@@ -129,10 +132,12 @@ summary: A simple observer implementation for POROs (Plain Old Ruby Object) and
129
132
  test_files:
130
133
  - spec/signal/activerecord_spec.rb
131
134
  - spec/signal/call_spec.rb
135
+ - spec/signal/issues/2_spec.rb
132
136
  - spec/signal/listener_spec.rb
133
137
  - spec/signal/signal_spec.rb
134
138
  - spec/spec_helper.rb
135
139
  - spec/support/callable.rb
140
+ - spec/support/emitter.rb
136
141
  - spec/support/observable.rb
137
142
  - spec/support/observable_with_call.rb
138
143
  - spec/support/user.rb
data/lib/signal/call.rb DELETED
@@ -1,21 +0,0 @@
1
- module Signal
2
- def self.call
3
- Call
4
- end
5
-
6
- module Call
7
- def self.included(target)
8
- target.include(Signal)
9
- target.extend(ClassMethods)
10
- end
11
-
12
- module ClassMethods
13
- def call(*args, &block)
14
- new(*args).tap do |instance|
15
- yield(instance)
16
- instance.call
17
- end
18
- end
19
- end
20
- end
21
- end