Class: Onuro::Engine

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/onuro/engine.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#logger, logger, logger_file

Constructor Details

#initializeEngine

Returns a new instance of Engine.



45
46
47
48
49
# File 'lib/onuro/engine.rb', line 45

def initialize
  # Loading events from the global configuration, if we have it
  # We need to clone, otherwise will get the smae obejct_id reference
  self.events = Engine.configuration.events.clone
end

Class Attribute Details

.configurationObject

Returns the global [EngineConfiguration](Onuro/EngineConfiguration) object. While you can use this method to access the configuration, the more common convention is to use [Onuro::Engine.configure](Onuro::Engine#configure-class_method).

Examples:

Onuro::Engine.configuration.tbd = 1234

See Also:



22
23
24
# File 'lib/onuro/engine.rb', line 22

def self.configuration
  @configuration ||= Onuro::EngineConfiguration.new
end

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



7
8
9
# File 'lib/onuro/engine.rb', line 7

def events
  @events
end

Class Method Details

.configure {|EngineConfiguration| ... } ⇒ Object

Yields the global configuration to a block.

Examples:

Onuro::Engine.configure do |config|
  config.events 'documentation'
end

Yields:

See Also:



41
42
43
# File 'lib/onuro/engine.rb', line 41

def self.configure
  yield configuration if block_given?
end

.instanceObject



51
52
53
# File 'lib/onuro/engine.rb', line 51

def self.instance
  new
end

.resetObject

Users must invoke this if they want to have the configuration reset when they use the runner multiple times within the same process. Users must deal themselves with re-configuration of Onuro::Engine before run.



29
30
31
# File 'lib/onuro/engine.rb', line 29

def self.reset
  @configuration = nil
end

Instance Method Details

#add_event(event) ⇒ Object



55
56
57
58
# File 'lib/onuro/engine.rb', line 55

def add_event(event)
  events[event.name] = event
  self
end

#add_events(new_events) ⇒ Object



60
61
62
63
# File 'lib/onuro/engine.rb', line 60

def add_events(new_events)
  new_events.each { |event| add_event(event) }
  self
end

#delete_event!(event_name) ⇒ Object



69
70
71
72
# File 'lib/onuro/engine.rb', line 69

def delete_event!(event_name)
  result = events.delete(event_name)
  raise InvalidEventNameException unless result
end

#event?(event_name) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/onuro/engine.rb', line 65

def event?(event_name)
  events.key?(event_name)
end

#execute(event_name, context = Context.new) ⇒ Object



74
75
76
77
78
79
# File 'lib/onuro/engine.rb', line 74

def execute(event_name, context = Context.new)
  raise InvalidEventNameException unless event?(event_name)

  context.data.merge! ContextBuilder.build.data
  events[event_name].execute(context)
end