class Onuro::Engine

Attributes

configuration[W]

Setter for shared global objects

events[RW]

Public Class Methods

configuration() click to toggle source

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).

@example

Onuro::Engine.configuration.tbd = 1234

@see Onuro::Engine.configure @see Onuro::EngineConfiguration

# File lib/onuro/engine.rb, line 22
def self.configuration
  @configuration ||= Onuro::EngineConfiguration.new
end
configure() { |configuration| ... } click to toggle source

Yields the global configuration to a block. @yield [EngineConfiguration] global configuration

@example

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

@see Onuro::EngineConfiguration

# File lib/onuro/engine.rb, line 41
def self.configure
  yield configuration if block_given?
end
instance() click to toggle source
# File lib/onuro/engine.rb, line 51
def self.instance
  new
end
new() click to toggle source
# 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
reset() click to toggle source

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.

# File lib/onuro/engine.rb, line 29
def self.reset
  @configuration = nil
end

Public Instance Methods

add_event(event) click to toggle source
# File lib/onuro/engine.rb, line 55
def add_event(event)
  events[event.name] = event
  self
end
add_events(new_events) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/onuro/engine.rb, line 65
def event?(event_name)
  events.key?(event_name)
end
execute(event_name, context = Context.new) click to toggle source
# 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