Class: Controll::Flow::EventMapper::Util

Inherits:
Object
  • Object
show all
Includes:
Event::Helper
Defined in:
lib/controll/flow/event_mapper/util.rb

Constant Summary collapse

NoMappingFoundError =
Controll::Flow::NoMappingFoundError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Event::Helper

#create_event, #normalize

Constructor Details

#initialize(event, event_map) ⇒ Util

Returns a new instance of Util.



8
9
10
11
12
13
14
15
# File 'lib/controll/flow/event_mapper/util.rb', line 8

def initialize event, event_map
  @event ||= normalize event

  unless valid_map? event_map
    raise ArgumentError, "Invalid redirect map: #{event_map}, must be a non-empty Hash" 
  end
  @event_map ||= event_map
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



4
5
6
# File 'lib/controll/flow/event_mapper/util.rb', line 4

def event
  @event
end

#event_mapObject (readonly)

Returns the value of attribute event_map.



4
5
6
# File 'lib/controll/flow/event_mapper/util.rb', line 4

def event_map
  @event_map
end

Instance Method Details

#map_eventObject

An event can also be a Symbol, in which case it is a :notice event



19
20
21
22
23
24
# File 'lib/controll/flow/event_mapper/util.rb', line 19

def map_event
  event_map.each do |path, events|            
    return path.to_s if valid? events
  end
  raise NoMappingFoundError, "No path could be found for event: #{event.inspect} in map: #{event_map}" 
end