Sha256: d361d9a9a671c26c80b9750ddc3aceeaab5c118e4e3bf5c6dc504db3bcd61d2c

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 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)
          super(workflow)
          @step = {
            name: name,
            order: order,
            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)
          lookup_prompt = get_prompt_content(prompt)

          @step[:prompt] = lookup_prompt || prompt
          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

1 entries across 1 versions & 1 rubygems

Version Path
ad-agent_architecture-0.0.22 lib/ad/agent_architecture/dsl/step_dsl.rb