reorm 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/lib/reorm/modules/event_modules.rb +18 -10
- data/lib/reorm/version.rb +1 -1
- data/spec/reorm/modules/event_source_spec.rb +9 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1918c9ecdd0e0a161e62b8587b254e1a9679b052
|
4
|
+
data.tar.gz: aeb3dd4474c0aee5e7fd42b681ab12941114fa31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1605bae7dc2d7fd475f8e042cc291da4b56a069291a84462bec879a772b2261088d270bae06431afd263689acc3900f92e887f7d59c49be44f08c006a31715a6
|
7
|
+
data.tar.gz: c3be7ca8d516f9da9c6450b34afabb6bbf9f8805c28872719a691835df6a4729bafeaf5c7a019c6ea6043313259ae793a7095ccd7a203d9f2007144aa6e5f171
|
@@ -8,8 +8,7 @@ module Reorm
|
|
8
8
|
@@class_events = {}
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
module EventHandler
|
11
|
+
module SpecifyEventHandlers
|
13
12
|
include EventData
|
14
13
|
|
15
14
|
def after_create(*methods)
|
@@ -45,13 +44,18 @@ module Reorm
|
|
45
44
|
end
|
46
45
|
|
47
46
|
def store_event_handlers(event, *methods)
|
48
|
-
if
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
47
|
+
@@class_events[self] = {} if !@@class_events.include?(self)
|
48
|
+
@@class_events[self][event] = [] if !@@class_events[self].include?(event)
|
49
|
+
@@class_events[self][event] = @@class_events[self][event].concat(methods).uniq
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# A module that defines the class level methods for setting event handlers.
|
54
|
+
module EventHandler
|
55
|
+
include EventData
|
56
|
+
|
57
|
+
def EventHandler.included(target)
|
58
|
+
target.extend(SpecifyEventHandlers)
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
@@ -69,7 +73,7 @@ module Reorm
|
|
69
73
|
if handlers.include?(event)
|
70
74
|
handlers[event].each do |handler|
|
71
75
|
if !object.respond_to?(handler)
|
72
|
-
raise Error, "Unable to locate a method called '#{
|
76
|
+
raise Error, "Unable to locate a method called '#{handler}' for an instance of the #{object.class.name} class."
|
73
77
|
end
|
74
78
|
object.__send__(handler)
|
75
79
|
end
|
@@ -78,5 +82,9 @@ module Reorm
|
|
78
82
|
end
|
79
83
|
end
|
80
84
|
end
|
85
|
+
|
86
|
+
def EventSource.included(target)
|
87
|
+
target.extend(EventSource)
|
88
|
+
end
|
81
89
|
end
|
82
90
|
end
|
data/lib/reorm/version.rb
CHANGED
@@ -3,8 +3,9 @@ require "spec_helper"
|
|
3
3
|
class EventSourceTest
|
4
4
|
include Reorm::EventHandler
|
5
5
|
include Reorm::EventSource
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
before_create :event_handler
|
8
|
+
before_validate :does_not_exist
|
8
9
|
|
9
10
|
def initialize
|
10
11
|
@count = 0
|
@@ -30,14 +31,6 @@ describe EventSourceTest do
|
|
30
31
|
end
|
31
32
|
|
32
33
|
describe "#fire_events()" do
|
33
|
-
describe "called at the instance level" do
|
34
|
-
it "calls methods assigned to events when those events are fired" do
|
35
|
-
subject.before_create :event_handler
|
36
|
-
subject.fire_events(events: [:before_create])
|
37
|
-
expect(subject.count).to eq(1)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
34
|
describe "called at the class level" do
|
42
35
|
it "calls methods assigned to events when those events are fired" do
|
43
36
|
EventSourceTest.before_create :event_handler
|
@@ -45,5 +38,11 @@ describe EventSourceTest do
|
|
45
38
|
expect(subject.count).to eq(1)
|
46
39
|
end
|
47
40
|
end
|
41
|
+
|
42
|
+
it "raises an exception if an event that has been specified does not exist" do
|
43
|
+
expect {
|
44
|
+
subject.fire_events(target: subject, events: [:before_validate])
|
45
|
+
}.to raise_exception(Reorm::Error, "Unable to locate a method called 'does_not_exist' for an instance of the EventSourceTest class.")
|
46
|
+
end
|
48
47
|
end
|
49
48
|
end
|