Sha256: c52ca38a5906fd67a5a7f2396079eff1bf44e38d0cb4c0eb9d0ab9a6d4b77e61

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

# file: lib/ad/agent_architecture/dsl/step_dsl.rb

# frozen_string_literal: true

module Ad
  module AgentArchitecture
    module Dsl
      # This class is responsible for defining the steps of a section
      class StepDsl < ChildDsl
        attr_reader :section
        attr_reader :step

        def initialize(workflow, section, name, order, description: nil)
          super(workflow)
          @step = {
            name: name,
            order: order,
            description: description,
            prompt: '',
            input_attributes: [],
            output_attributes: []
          }

          @section = section
          @section[:steps] << @step
        end

        def input(name, **_opts)
          infer_attribute(name)
          @step[:input_attributes] << name
          self
        end

        def output(name, **_opts)
          infer_attribute(name)
          @step[:output_attributes] << name
          self
        end

        def prompt(prompt, **_opts)
          content = prompt_content(prompt)
          @step[:prompt] = content || prompt
          self
        end

        def description(description)
          @step[:description] = description
          self
        end

        private

        def infer_attribute(name)
          raise ArgumentError, 'Attribute name must be a string or symbol' unless name.is_a?(String) || name.is_a?(Symbol)

          return if attributes.key?(name)

          # May want to add more sophisticated type inference here
          type = name.to_s.end_with?('s') ? 'array' : 'string'
          attributes[name] = { name: name, type: type, is_array: type == 'array' }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ad-agent_architecture-0.0.24 lib/ad/agent_architecture/dsl/step_dsl.rb
ad-agent_architecture-0.0.23 lib/ad/agent_architecture/dsl/step_dsl.rb