ventable 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ventable/event.rb +10 -6
- data/lib/ventable/version.rb +1 -1
- data/spec/ventable/ventable_spec.rb +12 -0
- metadata +2 -2
data/lib/ventable/event.rb
CHANGED
@@ -28,8 +28,10 @@ module ::Ventable
|
|
28
28
|
around_block = observer_entry[:around_block]
|
29
29
|
inside_block = -> { notify_observer_set(observer_entry[:observers]) }
|
30
30
|
around_block.call(inside_block)
|
31
|
-
|
31
|
+
elsif observer_entry
|
32
32
|
notify_observer(observer_entry)
|
33
|
+
else
|
34
|
+
raise Ventable::Error.new("nil in observer_entry set #{observer_set.inspect}!")
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -44,9 +46,9 @@ module ::Ventable
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def notify_class_observer(observer)
|
47
|
-
observer.respond_to?(self.class.default_callback_method)
|
48
|
-
|
49
|
-
|
49
|
+
return observer.send(self.class.default_callback_method, self) if observer.respond_to?(self.class.default_callback_method)
|
50
|
+
return observer.send(:handle_event, self) if observer.respond_to?(:handle_event)
|
51
|
+
raise Ventable::Error.new("suitable event handler method found in observer #{self.inspect}")
|
50
52
|
end
|
51
53
|
|
52
54
|
module ClassMethods
|
@@ -65,12 +67,14 @@ module ::Ventable
|
|
65
67
|
end
|
66
68
|
observer_set = observer_entry[:observers]
|
67
69
|
end
|
68
|
-
|
70
|
+
raise Ventable::Error.new("found nil observer in params #{observer_list.inspect}") if observer_list.any?{|l| l.nil?}
|
71
|
+
observer_list.compact.each { |o| observer_set << o } unless observer_list.empty?
|
69
72
|
observer_set << block if block
|
70
73
|
end
|
71
74
|
|
72
75
|
def group(name, &block)
|
73
|
-
|
76
|
+
g = find_observer_group(name)
|
77
|
+
raise "Group #{name} already defined by #{g}" if g
|
74
78
|
self.observers <<
|
75
79
|
{ name: name,
|
76
80
|
around_block: block,
|
data/lib/ventable/version.rb
CHANGED
@@ -107,7 +107,9 @@ describe Ventable do
|
|
107
107
|
|
108
108
|
transaction_called.should be_true
|
109
109
|
observer_block_called.should be_true
|
110
|
+
transaction_called.should be_true
|
110
111
|
transaction_already_completed.should be_false
|
112
|
+
|
111
113
|
event_inside.should_not be_nil
|
112
114
|
event_inside.should be_a(TestEvent)
|
113
115
|
end
|
@@ -186,5 +188,15 @@ describe Ventable do
|
|
186
188
|
e.class.should == Ventable::Error
|
187
189
|
end
|
188
190
|
end
|
191
|
+
it "throws exception if nil observer added to the list" do
|
192
|
+
begin
|
193
|
+
TestEvent.configure do
|
194
|
+
notifies nil
|
195
|
+
end
|
196
|
+
fail "Shouldn't reach here, must throw a valid exception"
|
197
|
+
rescue Exception => e
|
198
|
+
e.class.should == Ventable::Error
|
199
|
+
end
|
200
|
+
end
|
189
201
|
end
|
190
202
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ventable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|