Module: ActiveProjection::ProjectionType
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/active_projection/projection_type.rb
Defined Under Namespace
Classes: WrongArgumentsCountError
Instance Method Summary
collapse
Instance Method Details
#evaluate(headers) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/active_projection/projection_type.rb', line 22
def evaluate()
return false unless solid? || [:replayed]
last_id = fetch_last_id
event_id = [:id]
case
when last_id + 1 == event_id
true
when last_id >= event_id
LOGGER.debug "[#{self.class.name}] event #{event_id} already processed"
false
when last_id < event_id
set_broken
LOGGER.debug "[#{self.class.name}] #{event_id - last_id} events are missing"
false
end
end
|
#initialize ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/active_projection/projection_type.rb', line 10
def initialize
self.handlers = Hash.new do |hash, key|
hash[key] = []
end
self.class.public_instance_methods(false).each do |method_name|
method = self.class.instance_method method_name
raise WrongArgumentsCountError if 2 < method.arity or method.arity < 1
event_type = ProjectionType.method_name_to_event_type method_name
handlers[event_type] << [method_name, method.arity]
end
end
|
#invoke(event, headers) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/active_projection/projection_type.rb', line 39
def invoke(event, )
event_id = [:id]
event_type = event.class.name.to_sym
handlers[event_type].each do |method, arity|
begin
if 1 == arity
self.send method, event
else
self.send method, event,
end
rescue Exception
LOGGER.debug "[#{self.class.name}] error processing #{event_type}[#{event_id}]"
raise
end
end
update_last_id event_id
LOGGER.debug "[#{self.class.name}] sucessfully processed #{event_type}[#{event_id}]"
end
|