Class: Observed::Context
- Inherits:
-
Object
- Object
- Observed::Context
- Defined in:
- lib/observed/context.rb
Overview
The run context of an Observed system. It can be initialized via parameters to automatically configure the system and everything needed such as the config builder, the DSL, the logger, etc.
Instance Method Summary collapse
- #config_builder ⇒ Object
- #config_dsl ⇒ Object
- #configure(args) ⇒ Object
- #event_bus ⇒ Object
- #executor ⇒ Object
-
#initialize(args = {}) ⇒ Context
constructor
A new instance of Context.
- #logger ⇒ Object
- #observed_task_factory ⇒ Object
- #system ⇒ Object
- #task_factory ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Context
Returns a new instance of Context.
15 16 17 |
# File 'lib/observed/context.rb', line 15 def initialize(args={}) configure args end |
Instance Method Details
#config_builder ⇒ Object
64 65 66 |
# File 'lib/observed/context.rb', line 64 def config_builder @config_builder ||= Observed::ConfigBuilder.new(system: system, logger: logger, context: self) end |
#config_dsl ⇒ Object
68 69 70 |
# File 'lib/observed/context.rb', line 68 def config_dsl Observed::ConfigDSL.new(builder: config_builder, logger: logger) end |
#configure(args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/observed/context.rb', line 19 def configure(args) @logger ||= begin logger_out = if args[:log_file] File.open(args[:log_file], 'a') else STDOUT end Logger.new(logger_out) end @executor = args[:executor] set_log_level_to_debug(!!args[:debug]) if args[:config_file] load_config_file(args[:config_file]) end self end |
#event_bus ⇒ Object
52 53 54 |
# File 'lib/observed/context.rb', line 52 def event_bus @event_bus ||= Observed::EventBus.new(task_factory: task_factory) end |
#executor ⇒ Object
48 49 50 |
# File 'lib/observed/context.rb', line 48 def executor @executor ||= Observed::BlockingExecutor.new end |
#logger ⇒ Object
40 41 42 |
# File 'lib/observed/context.rb', line 40 def logger @logger end |
#observed_task_factory ⇒ Object
60 61 62 |
# File 'lib/observed/context.rb', line 60 def observed_task_factory @observed_task_factory ||= Observed::ObservedTaskFactory.new(task_factory: task_factory) end |
#system ⇒ Object
44 45 46 |
# File 'lib/observed/context.rb', line 44 def system @system ||= Observed::System.new(logger: logger, context: self) end |
#task_factory ⇒ Object
56 57 58 |
# File 'lib/observed/context.rb', line 56 def task_factory @task_factory ||= Observed::TaskFactory.new(executor: executor) end |