signal 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +51 -0
- data/README.md +4 -4
- data/lib/signal/active_record.rb +12 -12
- data/lib/signal/listener.rb +4 -3
- data/lib/signal/version.rb +1 -1
- data/spec/signal_spec.rb +31 -11
- data/spec/support/callable.rb +1 -1
- metadata +14 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cbd0a814de4e6237f0b61910db55ee771bd2ed84
|
4
|
+
data.tar.gz: ac8b02d08b219eaac0850e4ae57fa054ec4d0053
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18d186c33d95751a355b9d16ff120bc9f88c2c0e9003897fee839b2643f68c9de61448729cceab114db489495cbfa9da28618038bd5c9b1693bfc759e5a4c0ec
|
7
|
+
data.tar.gz: cb6c62d5f1fb096e09b76ecbb36d3ef0eaf9140ed57ca662f65a65f8203a547497cd438995b042abad83957b37cffcc743fc11a03938cc7c32e88d238b87f836
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source "http://rubygems.org"
|
2
2
|
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
signal (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (4.0.0)
|
10
|
+
activesupport (= 4.0.0)
|
11
|
+
builder (~> 3.1.0)
|
12
|
+
activerecord (4.0.0)
|
13
|
+
activemodel (= 4.0.0)
|
14
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
15
|
+
activesupport (= 4.0.0)
|
16
|
+
arel (~> 4.0.0)
|
17
|
+
activerecord-deprecated_finders (1.0.3)
|
18
|
+
activesupport (4.0.0)
|
19
|
+
i18n (~> 0.6, >= 0.6.4)
|
20
|
+
minitest (~> 4.2)
|
21
|
+
multi_json (~> 1.3)
|
22
|
+
thread_safe (~> 0.1)
|
23
|
+
tzinfo (~> 0.3.37)
|
24
|
+
arel (4.0.0)
|
25
|
+
atomic (1.1.10)
|
26
|
+
builder (3.1.4)
|
27
|
+
diff-lcs (1.2.4)
|
28
|
+
i18n (0.6.4)
|
29
|
+
minitest (4.7.5)
|
30
|
+
multi_json (1.7.7)
|
31
|
+
rspec (2.14.1)
|
32
|
+
rspec-core (~> 2.14.0)
|
33
|
+
rspec-expectations (~> 2.14.0)
|
34
|
+
rspec-mocks (~> 2.14.0)
|
35
|
+
rspec-core (2.14.3)
|
36
|
+
rspec-expectations (2.14.0)
|
37
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
38
|
+
rspec-mocks (2.14.1)
|
39
|
+
sqlite3 (1.3.7)
|
40
|
+
thread_safe (0.1.0)
|
41
|
+
atomic
|
42
|
+
tzinfo (0.3.37)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
activerecord
|
49
|
+
rspec
|
50
|
+
signal!
|
51
|
+
sqlite3
|
data/README.md
CHANGED
@@ -123,10 +123,10 @@ class Thing < ActiveRecord::Base
|
|
123
123
|
end
|
124
124
|
|
125
125
|
thing = Thing.new(:name => "Stuff")
|
126
|
-
thing.on(:create) { puts updated_at, name }
|
127
|
-
thing.on(:update) { puts updated_at, name }
|
128
|
-
thing.on(:remove) { puts destroyed? }
|
129
|
-
thing.on(:validation) { p errors.full_messages }
|
126
|
+
thing.on(:create) {|thing| puts thing.updated_at, thing.name }
|
127
|
+
thing.on(:update) {|thing| puts thing.updated_at, thing.name }
|
128
|
+
thing.on(:remove) {|thing| puts thing.destroyed? }
|
129
|
+
thing.on(:validation) {|thing| p thing.errors.full_messages }
|
130
130
|
|
131
131
|
thing.save!
|
132
132
|
#=> 2013-01-26 10:32:39 -0200
|
data/lib/signal/active_record.rb
CHANGED
@@ -16,11 +16,11 @@ module Signal
|
|
16
16
|
module InstanceMethods
|
17
17
|
private
|
18
18
|
def around_create_signal
|
19
|
-
emit_signal(:before, :create)
|
19
|
+
emit_signal(:before, :create, self)
|
20
20
|
yield
|
21
21
|
return unless persisted?
|
22
|
-
emit_signal(:on, :create)
|
23
|
-
emit_signal(:after, :create)
|
22
|
+
emit_signal(:on, :create, self)
|
23
|
+
emit_signal(:after, :create, self)
|
24
24
|
end
|
25
25
|
|
26
26
|
def around_save_signal
|
@@ -29,26 +29,26 @@ module Signal
|
|
29
29
|
return
|
30
30
|
end
|
31
31
|
|
32
|
-
emit_signal(:before, :update)
|
32
|
+
emit_signal(:before, :update, self)
|
33
33
|
yield
|
34
|
-
emit_signal(:on, :update)
|
35
|
-
emit_signal(:after, :update)
|
34
|
+
emit_signal(:on, :update, self)
|
35
|
+
emit_signal(:after, :update, self)
|
36
36
|
end
|
37
37
|
|
38
38
|
def around_destroy_signal
|
39
|
-
emit_signal(:before, :remove)
|
39
|
+
emit_signal(:before, :remove, self)
|
40
40
|
yield
|
41
|
-
emit_signal(:on, :remove)
|
42
|
-
emit_signal(:after, :remove)
|
41
|
+
emit_signal(:on, :remove, self)
|
42
|
+
emit_signal(:after, :remove, self)
|
43
43
|
end
|
44
44
|
|
45
45
|
def before_validation_signal
|
46
|
-
emit_signal(:before, :validation)
|
46
|
+
emit_signal(:before, :validation, self)
|
47
47
|
end
|
48
48
|
|
49
49
|
def after_validation_signal
|
50
|
-
emit_signal(:on, :validation) if errors.any?
|
51
|
-
emit_signal(:after, :validation)
|
50
|
+
emit_signal(:on, :validation, self) if errors.any?
|
51
|
+
emit_signal(:after, :validation, self)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
data/lib/signal/listener.rb
CHANGED
@@ -8,9 +8,10 @@ module Signal
|
|
8
8
|
@event_method = :"#{@type}_#{@event}"
|
9
9
|
end
|
10
10
|
|
11
|
-
def method_missing(
|
12
|
-
return super unless
|
13
|
-
@context.instance_exec(*args, &@block)
|
11
|
+
def method_missing(method_name, *args)
|
12
|
+
return super unless respond_to_missing?(method_name, false)
|
13
|
+
# @context.instance_exec(*args, &@block)
|
14
|
+
@block.call(*args)
|
14
15
|
end
|
15
16
|
|
16
17
|
def to_s
|
data/lib/signal/version.rb
CHANGED
data/spec/signal_spec.rb
CHANGED
@@ -7,42 +7,42 @@ describe Signal do
|
|
7
7
|
context "using blocks" do
|
8
8
|
it "triggers event" do
|
9
9
|
observable.on(:ready, &callable)
|
10
|
-
callable.should_receive(:called).with(
|
10
|
+
callable.should_receive(:called).with(no_args)
|
11
11
|
|
12
12
|
observable.emit(:ready)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "triggers event with arguments" do
|
16
16
|
observable.on(:ready, &callable)
|
17
|
-
callable.should_receive(:called).with(
|
17
|
+
callable.should_receive(:called).with(1, 2, 3)
|
18
18
|
|
19
19
|
observable.emit(:ready, 1, 2, 3)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "triggers before event" do
|
23
23
|
observable.before(:ready, &callable)
|
24
|
-
callable.should_receive(:called).with(
|
24
|
+
callable.should_receive(:called).with(no_args)
|
25
25
|
|
26
26
|
observable.emit(:ready)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "triggers before event with arguments" do
|
30
30
|
observable.before(:ready, &callable)
|
31
|
-
callable.should_receive(:called).with(
|
31
|
+
callable.should_receive(:called).with(1, 2, 3)
|
32
32
|
|
33
33
|
observable.emit(:ready, 1, 2, 3)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "triggers after event" do
|
37
37
|
observable.after(:ready, &callable)
|
38
|
-
callable.should_receive(:called).with(
|
38
|
+
callable.should_receive(:called).with(no_args)
|
39
39
|
|
40
40
|
observable.emit(:ready)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "triggers after event with arguments" do
|
44
44
|
observable.after(:ready, &callable)
|
45
|
-
callable.should_receive(:called).with(
|
45
|
+
callable.should_receive(:called).with(1, 2, 3)
|
46
46
|
|
47
47
|
observable.emit(:ready, 1, 2, 3)
|
48
48
|
end
|
@@ -57,19 +57,39 @@ describe Signal do
|
|
57
57
|
.on(:ready, &on_callable)
|
58
58
|
.after(:ready, &after_callable)
|
59
59
|
|
60
|
-
before_callable
|
61
|
-
|
62
|
-
|
60
|
+
before_callable
|
61
|
+
.should_receive(:called)
|
62
|
+
.with(no_args)
|
63
|
+
.ordered
|
64
|
+
|
65
|
+
on_callable
|
66
|
+
.should_receive(:called)
|
67
|
+
.with(no_args)
|
68
|
+
.ordered
|
69
|
+
|
70
|
+
after_callable
|
71
|
+
.should_receive(:called)
|
72
|
+
.with(no_args)
|
73
|
+
.ordered
|
63
74
|
|
64
75
|
observable.emit(:ready)
|
65
76
|
end
|
77
|
+
|
78
|
+
it "keeps context" do
|
79
|
+
context = nil
|
80
|
+
callable = -> { context = self }
|
81
|
+
observable.on(:ready, &callable)
|
82
|
+
observable.emit(:ready)
|
83
|
+
|
84
|
+
expect(context).to eql(self)
|
85
|
+
end
|
66
86
|
end
|
67
87
|
|
68
88
|
context "using listeners" do
|
69
89
|
it "triggers event for listener" do
|
70
90
|
callable.respond_to(:on_ready)
|
71
91
|
observable.listeners << callable
|
72
|
-
callable.should_receive(:called).with(
|
92
|
+
callable.should_receive(:called).with(no_args)
|
73
93
|
|
74
94
|
observable.emit(:ready)
|
75
95
|
end
|
@@ -77,7 +97,7 @@ describe Signal do
|
|
77
97
|
it "triggers event for listener with arguments" do
|
78
98
|
callable.respond_to(:on_ready)
|
79
99
|
observable.listeners << callable
|
80
|
-
callable.should_receive(:called).with(
|
100
|
+
callable.should_receive(:called).with(1, 2, 3)
|
81
101
|
|
82
102
|
observable.emit(:ready, 1, 2, 3)
|
83
103
|
end
|
data/spec/support/callable.rb
CHANGED
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: signal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nando Vieira
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-07-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: sqlite3
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: A simple observer implementation for POROs (Plain Old Ruby Object) and
|
@@ -70,6 +63,7 @@ files:
|
|
70
63
|
- .gitignore
|
71
64
|
- .rspec
|
72
65
|
- Gemfile
|
66
|
+
- Gemfile.lock
|
73
67
|
- LICENSE.txt
|
74
68
|
- README.md
|
75
69
|
- Rakefile
|
@@ -92,27 +86,26 @@ files:
|
|
92
86
|
- spec/support/user.rb
|
93
87
|
homepage: http://github.com/fnando/signal
|
94
88
|
licenses: []
|
89
|
+
metadata: {}
|
95
90
|
post_install_message:
|
96
91
|
rdoc_options: []
|
97
92
|
require_paths:
|
98
93
|
- lib
|
99
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
95
|
requirements:
|
102
|
-
- -
|
96
|
+
- - '>='
|
103
97
|
- !ruby/object:Gem::Version
|
104
98
|
version: '0'
|
105
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
100
|
requirements:
|
108
|
-
- -
|
101
|
+
- - '>='
|
109
102
|
- !ruby/object:Gem::Version
|
110
103
|
version: '0'
|
111
104
|
requirements: []
|
112
105
|
rubyforge_project:
|
113
|
-
rubygems_version:
|
106
|
+
rubygems_version: 2.0.3
|
114
107
|
signing_key:
|
115
|
-
specification_version:
|
108
|
+
specification_version: 4
|
116
109
|
summary: A simple observer implementation for POROs (Plain Old Ruby Object) and ActiveRecord
|
117
110
|
objects.
|
118
111
|
test_files:
|