/
path_finder.rb
36 lines (29 loc) · 973 Bytes
/
path_finder.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Controll::Flow
module EventMapper
class PathFinder
attr_accessor :event, :maps, :types
NoMappingFoundError = Controll::Flow::NoMappingFoundError
# event <Event>
def initialize event, maps, types = []
raise ArgumentError, "Event argument must not be empty" if event.blank?
raise ArgumentError, "Maps argument must not be empty" if maps.blank?
@event = normalize event
@types = types unless types.blank?
@maps = maps
end
def path
@path ||= mapper.map_event
rescue StandardError => e
raise NoMappingFoundError, "No event mapping could be found for: #{event.inspect} in: #{maps}. Cause: #{e}"
end
protected
include Controll::Event::Helper
def event_map
@event_map ||= maps[event.type] || {}
end
def mapper
@mapper ||= Controll::Flow::EventMapper::Util.new event, event_map
end
end
end
end