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 +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/lib/signal.rb +3 -3
- data/lib/signal/{active_record.rb → extensions/active_record.rb} +16 -13
- data/lib/signal/extensions/call.rb +23 -0
- data/lib/signal/version.rb +1 -1
- data/spec/signal/activerecord_spec.rb +1 -1
- data/spec/signal/call_spec.rb +1 -1
- data/spec/signal/issues/2_spec.rb +13 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/emitter.rb +9 -0
- data/spec/support/user.rb +1 -1
- metadata +9 -4
- data/lib/signal/call.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0da1e84da778b581b1e7b325a1437ecc720f56ca
|
4
|
+
data.tar.gz: d1356905f81403f12aac8bebc3205ffb1c031f74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dd9dc2736009aefe24b4aa0dea8d4febd50a3ab9c6b0a8b5eadb95c15e513007c8fedb0bf332809e229e38a0606059b9a8f2a44507f74a47bfabfcb788fbac1
|
7
|
+
data.tar.gz: 292aa7515e1e260860a298da7680235e5418462301042d260d44bc23b0016619eeec6654cc5c045a2ce2527b17b13a1dec9d6808b6f1c2fa67d889c7646057ce
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
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
|
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
|
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,19 +1,22 @@
|
|
1
1
|
module Signal
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
data/lib/signal/version.rb
CHANGED
data/spec/signal/call_spec.rb
CHANGED
@@ -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
data/spec/support/user.rb
CHANGED
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.
|
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-
|
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
|