Object
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.
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
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
# 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
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
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
# 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
Generated with the Darkfish Rdoc Generator 2.