Class: SmartPrompt::Engine
- Inherits:
-
Object
- Object
- SmartPrompt::Engine
- Defined in:
- lib/smart_prompt/engine.rb
Instance Attribute Summary collapse
-
#adapters ⇒ Object
readonly
Returns the value of attribute adapters.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
#current_adapter ⇒ Object
readonly
Returns the value of attribute current_adapter.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
- #call_worker(worker_name, params = {}) ⇒ Object
-
#initialize(config_file) ⇒ Engine
constructor
A new instance of Engine.
- #load_config(config_file) ⇒ Object
- #load_workers ⇒ Object
Constructor Details
#initialize(config_file) ⇒ Engine
Returns a new instance of Engine.
4 5 6 7 8 9 |
# File 'lib/smart_prompt/engine.rb', line 4 def initialize(config_file) @config_file = config_file @adapters={} @templates={} load_config(config_file) end |
Instance Attribute Details
#adapters ⇒ Object (readonly)
Returns the value of attribute adapters.
3 4 5 |
# File 'lib/smart_prompt/engine.rb', line 3 def adapters @adapters end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/smart_prompt/engine.rb', line 3 def config @config end |
#config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
3 4 5 |
# File 'lib/smart_prompt/engine.rb', line 3 def config_file @config_file end |
#current_adapter ⇒ Object (readonly)
Returns the value of attribute current_adapter.
3 4 5 |
# File 'lib/smart_prompt/engine.rb', line 3 def current_adapter @current_adapter end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
3 4 5 |
# File 'lib/smart_prompt/engine.rb', line 3 def templates @templates end |
Instance Method Details
#call_worker(worker_name, params = {}) ⇒ Object
31 32 33 34 |
# File 'lib/smart_prompt/engine.rb', line 31 def call_worker(worker_name, params = {}) worker = get_worker(worker_name) worker.execute(params) end |
#load_config(config_file) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/smart_prompt/engine.rb', line 11 def load_config(config_file) @config_file = config_file @config = YAML.load_file(config_file) @config['adapters'].each do |adapter_name, adapter_config| adapter_class = SmartPrompt.const_get("#{adapter_name.capitalize}Adapter") @adapters[adapter_name] = adapter_class.new(adapter_config) end @current_adapter = @config['default_adapter'] if @config['default_adapter'] @config['templates'].each do |template_name, template_file| @templates[template_name] = PromptTemplate.new(template_file) end load_workers end |
#load_workers ⇒ Object
25 26 27 28 29 |
# File 'lib/smart_prompt/engine.rb', line 25 def load_workers Dir.glob(File.join(@config['worker_path'], '*.rb')).each do |file| require(file) end end |