Class: Ad::AgentArchitecture::Dsl::AgentDsl
- Inherits:
-
Object
- Object
- Ad::AgentArchitecture::Dsl::AgentDsl
- Defined in:
- lib/ad/agent_architecture/dsl/agent_dsl.rb
Overview
This class is responsible for defining the agent DSL
Instance Attribute Summary collapse
-
#workflow ⇒ Object
readonly
Returns the value of attribute workflow.
-
#workflow_id ⇒ Object
Returns the value of attribute workflow_id.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes(&block) ⇒ Object
- #description(description) ⇒ Object
-
#initialize(name, description: nil) ⇒ AgentDsl
constructor
A new instance of AgentDsl.
- #prompts(&block) ⇒ Object
- #save ⇒ Object
- #save_json(file_name = nil) ⇒ Object
- #save_yaml(file_name = nil) ⇒ Object
- #section(name, description: nil, &block) ⇒ Object
- #settings(&block) ⇒ Object
Constructor Details
#initialize(name, description: nil) ⇒ AgentDsl
Returns a new instance of AgentDsl.
21 22 23 24 25 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 21 def initialize(name, description: nil) raise ArgumentError, 'Agent name must be a string or symbol' unless name.is_a?(String) || name.is_a?(Symbol) @workflow = WorkflowDsl.new(name, description: description) end |
Instance Attribute Details
#workflow ⇒ Object (readonly)
Returns the value of attribute workflow.
8 9 10 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 8 def workflow @workflow end |
#workflow_id ⇒ Object
Returns the value of attribute workflow_id.
9 10 11 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 9 def workflow_id @workflow_id end |
Class Method Details
.create(name, description: nil, &block) ⇒ Object
11 12 13 14 15 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 11 def self.create(name, description: nil, &block) new(name, description: description).tap do |dsl| dsl.instance_eval(&block) if block_given? end end |
Instance Method Details
#attributes(&block) ⇒ Object
31 32 33 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 31 def attributes(&block) @workflow.attributes(&block) end |
#description(description) ⇒ Object
17 18 19 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 17 def description(description) @workflow.description(description) end |
#prompts(&block) ⇒ Object
35 36 37 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 35 def prompts(&block) @workflow.prompts(&block) end |
#save ⇒ Object
45 46 47 48 49 50 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 45 def save id = Ad::AgentArchitecture::Dsl::Actions::SaveDatabase.new(@workflow).save @workflow_id = id self end |
#save_json(file_name = nil) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 52 def save_json(file_name = nil) full_file_name = file_name || 'workflow.json' raise ArgumentError, 'Workflow needs to be saved, befor you can save JSON' unless @workflow_id Ad::AgentArchitecture::Dsl::Actions::SaveJson.new(@workflow_id).save(full_file_name) self end |
#save_yaml(file_name = nil) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 61 def save_yaml(file_name = nil) full_file_name = file_name || 'workflow.yaml' raise ArgumentError, 'Workflow needs to be saved, befor you can save YAML' unless @workflow_id Ad::AgentArchitecture::Dsl::Actions::SaveYaml.new(@workflow_id).save(full_file_name) self end |
#section(name, description: nil, &block) ⇒ Object
39 40 41 42 43 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 39 def section(name, description: nil, &block) raise ArgumentError, 'Section name must be a string or symbol' unless name.is_a?(String) || name.is_a?(Symbol) @workflow.section(name, description: description, &block) end |
#settings(&block) ⇒ Object
27 28 29 |
# File 'lib/ad/agent_architecture/dsl/agent_dsl.rb', line 27 def settings(&block) @workflow.settings(&block) end |