Parent

Class/Module Index [+]

Quicksearch

Ruote::Context

A sort of internal registry, via a shared instance of this class, the worker and the engine can access subservices like parser, treechecker, wfid_generator and so on.

Constants

SERVICE_PREFIX

Attributes

engine[RW]
storage[R]
worker[RW]

Public Class Methods

new(storage, worker=nil) click to toggle source
# File lib/ruote/context.rb, line 43
def initialize (storage, worker=nil)

  @storage = storage
  @storage.context = self

  @engine = nil
  @worker = worker

  @services = {}

  initialize_services
end

Public Instance Methods

[](key) click to toggle source

Used for things like

if @context['ruby_eval_allowed']
  # ...
end
# File lib/ruote/context.rb, line 83
def [] (key)

  SERVICE_PREFIX.match(key) ? @services[key] : get_conf[key]
end
[]=(key, value) click to toggle source

Mostly used by engineconfigure

# File lib/ruote/context.rb, line 90
def []= (key, value)

  raise(
    ArgumentError.new('use context#add_service to register services')
  ) if SERVICE_PREFIX.match(key)

  cf = get_conf
  cf[key] = value
  @storage.put(cf)

  value
end
add_service(key, *args) click to toggle source
# File lib/ruote/context.rb, line 108
def add_service (key, *args)

  path, klass, opts = args

  key = "s_#{key}" unless SERVICE_PREFIX.match(key)

  service = if klass

    require(path) if path

    aa = [ self ]
    aa << opts if opts

    @services[key] = Ruote.constantize(klass).new(*aa)
  else

    @services[key] = path
  end

  self.class.class_eval %{ def #{key[2..-1]}; @services['#{key}']; end }
    #
    # This 'one-liner' will add an instance method to Context for this
    # service.
    #
    # If the service key is 's_dishwasher', then the service will be
    # available via Context#dishwasher.
    #
    # I.e. dishwasher = engine.context.dishwasher

  service
end
context() click to toggle source

A trick : in order to avoid

@context = o.respond_to?(:context) ? o.context : o
# or
#@context = o.is_a?(Ruote::Context) ? o : o.context

simply letting a context say its context is itself.

# File lib/ruote/context.rb, line 64
def context

  self
end
engine_id() click to toggle source

Returns the engine_id (as set in the configuration under the key "engine_id"), or, by default, "engine".

# File lib/ruote/context.rb, line 72
def engine_id

  get_conf['engine_id'] || 'engine'
end
keys() click to toggle source
# File lib/ruote/context.rb, line 103
def keys

  get_conf.keys
end
shutdown() click to toggle source

Takes care of shutting down every service registered in this context.

# File lib/ruote/context.rb, line 142
def shutdown

  @storage.shutdown if @storage.respond_to?(:shutdown)
  @worker.shutdown if @worker

  @services.values.each { |s| s.shutdown if s.respond_to?(:shutdown) }
end

Protected Instance Methods

default_conf() click to toggle source
# File lib/ruote/context.rb, line 167
def default_conf

  { 's_wfidgen' => [
      'ruote/id/mnemo_wfid_generator', 'Ruote::MnemoWfidGenerator' ],
    's_parser' => [
      'ruote/parser', 'Ruote::Parser' ],
    's_treechecker' => [
      'ruote/util/treechecker', 'Ruote::TreeChecker' ],
    's_expmap' => [
       'ruote/exp/expression_map', 'Ruote::ExpressionMap' ],
    's_tracker' => [
      'ruote/evt/tracker', 'Ruote::Tracker' ],
    's_plist' => [
      'ruote/part/participant_list', 'Ruote::ParticipantList' ],
    's_dispatch_pool' => [
      'ruote/part/dispatch_pool', 'Ruote::DispatchPool' ],
    's_logger' => [
      'ruote/log/wait_logger', 'Ruote::WaitLogger' ],
    's_error_handler' => [
      'ruote/error_handler', 'Ruote::ErrorHandler' ] }
end
get_conf() click to toggle source
# File lib/ruote/context.rb, line 152
def get_conf

  @storage.get_configuration('engine') || {}
end
initialize_services() click to toggle source
# File lib/ruote/context.rb, line 157
def initialize_services

  default_conf.merge(get_conf).each do |key, value|

    next unless SERVICE_PREFIX.match(key)

    add_service(key, *value)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.