evt-entity_projection 0.2.0.0 → 0.3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/entity_projection/controls/event_data.rb +1 -1
- data/lib/entity_projection/entity_projection.rb +38 -36
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d95cac2f4433102c6e103842c3090d76e15dfd7e
|
4
|
+
data.tar.gz: 8572642c0c05470a182a224b0a07e71c655bb05c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f5ba73316e7ce808eebb093767ab1d7dbe3027e439872975a3b7cd4b5573fa3fdce4663b4646f251f29a65c2562300163682b1e429568183ce28cd17fd8d433
|
7
|
+
data.tar.gz: ab267dd0bf149334ae5e1b1551a9fc6d2aae78549b05ced35b78550ba6e8d318b4052b071dd954ac20466415b87a278f786ab2fe453982d78c3c95427414b6ac
|
@@ -7,7 +7,7 @@ module EntityProjection
|
|
7
7
|
cls.extend Call
|
8
8
|
cls.extend Info
|
9
9
|
cls.extend ApplyMacro
|
10
|
-
cls.extend
|
10
|
+
cls.extend EventRegistry
|
11
11
|
cls.extend EntityNameMacro
|
12
12
|
|
13
13
|
virtual :configure
|
@@ -27,8 +27,8 @@ module EntityProjection
|
|
27
27
|
module Info
|
28
28
|
extend self
|
29
29
|
|
30
|
-
def handler(
|
31
|
-
name = handler_name(
|
30
|
+
def handler(event_or_event_data)
|
31
|
+
name = handler_name(event_or_event_data)
|
32
32
|
|
33
33
|
if method_defined?(name)
|
34
34
|
return name
|
@@ -37,17 +37,19 @@ module EntityProjection
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def handles?(
|
41
|
-
|
40
|
+
def handles?(event_or_event_data)
|
41
|
+
handler_name = self.handler_name(event_or_event_data)
|
42
|
+
|
43
|
+
method_defined?(handler_name)
|
42
44
|
end
|
43
45
|
|
44
|
-
def handler_name(
|
46
|
+
def handler_name(event_or_event_data)
|
45
47
|
name = nil
|
46
48
|
|
47
|
-
if
|
48
|
-
name = Messaging::Message::Info.canonize_name(
|
49
|
+
if event_or_event_data.is_a?(MessageStore::MessageData::Read)
|
50
|
+
name = Messaging::Message::Info.canonize_name(event_or_event_data.type)
|
49
51
|
else
|
50
|
-
name =
|
52
|
+
name = event_or_event_data.message_name
|
51
53
|
end
|
52
54
|
|
53
55
|
"apply_#{name}"
|
@@ -61,17 +63,17 @@ module EntityProjection
|
|
61
63
|
@logger ||= Log.get(self)
|
62
64
|
end
|
63
65
|
|
64
|
-
def apply_macro(
|
65
|
-
define_apply_method(
|
66
|
-
|
66
|
+
def apply_macro(event_class, &blk)
|
67
|
+
define_apply_method(event_class, &blk)
|
68
|
+
event_registry.register(event_class)
|
67
69
|
end
|
68
70
|
alias :apply :apply_macro
|
69
71
|
|
70
|
-
def define_apply_method(
|
71
|
-
apply_method_name = handler_name(
|
72
|
+
def define_apply_method(event_class, &blk)
|
73
|
+
apply_method_name = handler_name(event_class)
|
72
74
|
|
73
75
|
if blk.nil?
|
74
|
-
error_msg = "Handler for #{
|
76
|
+
error_msg = "Handler for #{event_class.name} is not correctly defined. It must have a block."
|
75
77
|
logger.error { error_msg }
|
76
78
|
raise Error, error_msg
|
77
79
|
end
|
@@ -81,7 +83,7 @@ module EntityProjection
|
|
81
83
|
apply_method = instance_method(apply_method_name)
|
82
84
|
|
83
85
|
unless apply_method.arity == 1
|
84
|
-
error_msg = "Handler for #{
|
86
|
+
error_msg = "Handler for #{event_class.name} is not correctly defined. It can only have a single parameter."
|
85
87
|
logger.error { error_msg }
|
86
88
|
raise Error, error_msg
|
87
89
|
end
|
@@ -91,15 +93,15 @@ module EntityProjection
|
|
91
93
|
end
|
92
94
|
|
93
95
|
module Call
|
94
|
-
def call(entity,
|
96
|
+
def call(entity, event_or_event_data)
|
95
97
|
instance = build(entity)
|
96
|
-
instance.(
|
98
|
+
instance.(event_or_event_data)
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
100
|
-
module
|
101
|
-
def
|
102
|
-
@
|
102
|
+
module EventRegistry
|
103
|
+
def event_registry
|
104
|
+
@event_registry ||= Messaging::MessageRegistry.new
|
103
105
|
end
|
104
106
|
end
|
105
107
|
|
@@ -112,28 +114,28 @@ module EntityProjection
|
|
112
114
|
alias :entity_name :entity_name_macro
|
113
115
|
end
|
114
116
|
|
115
|
-
def call(
|
116
|
-
if
|
117
|
-
|
117
|
+
def call(event_or_event_data)
|
118
|
+
if event_or_event_data.is_a?(Messaging::Message)
|
119
|
+
apply_event(event_or_event_data)
|
118
120
|
else
|
119
|
-
apply_event_data(
|
121
|
+
apply_event_data(event_or_event_data)
|
120
122
|
end
|
121
123
|
end
|
122
124
|
|
123
|
-
def
|
124
|
-
logger.trace(tags: [:apply, :message]) { "Applying
|
125
|
-
logger.trace(tags: [:data, :message, :apply]) {
|
125
|
+
def apply_event(event)
|
126
|
+
logger.trace(tags: [:apply, :message]) { "Applying event (Event class: #{event.class.name})" }
|
127
|
+
logger.trace(tags: [:data, :message, :apply]) { event.pretty_inspect }
|
126
128
|
|
127
|
-
handler = self.class.handler(
|
129
|
+
handler = self.class.handler(event)
|
128
130
|
|
129
131
|
unless handler.nil?
|
130
|
-
public_send(handler,
|
132
|
+
public_send(handler, event)
|
131
133
|
end
|
132
134
|
|
133
|
-
logger.info(tags: [:apply, :message]) { "Applied
|
134
|
-
logger.trace(tags: [:data, :message, :apply]) {
|
135
|
+
logger.info(tags: [:apply, :message]) { "Applied event (Event class: #{event.class.name})" }
|
136
|
+
logger.trace(tags: [:data, :message, :apply]) { event.pretty_inspect }
|
135
137
|
|
136
|
-
|
138
|
+
event
|
137
139
|
end
|
138
140
|
|
139
141
|
def apply_event_data(event_data)
|
@@ -145,9 +147,9 @@ module EntityProjection
|
|
145
147
|
handler = self.class.handler(event_data)
|
146
148
|
|
147
149
|
unless handler.nil?
|
148
|
-
|
149
|
-
|
150
|
-
res = Messaging::Message::Import.(event_data,
|
150
|
+
event_name = Messaging::Message::Info.canonize_name(event_data.type)
|
151
|
+
event_class = self.class.event_registry.get(event_name)
|
152
|
+
res = Messaging::Message::Import.(event_data, event_class)
|
151
153
|
public_send(handler, res)
|
152
154
|
else
|
153
155
|
if respond_to?(:apply)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-entity_projection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-messaging
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: evt-message_store-postgres
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: " "
|
42
56
|
email: opensource@eventide-project.org
|
43
57
|
executables: []
|