Module: Raix::PromptDeclarations::ClassMethods
- Defined in:
- lib/raix/prompt_declarations.rb
Overview
rubocop:disable Style/Documentation
Instance Method Summary collapse
-
#prompt(system: nil, call: nil, text: nil, stream: nil, success: nil, params: {}, if: nil, unless: nil, until: nil) ⇒ Object
Adds a prompt to the list of prompts.
- #prompts ⇒ Object
Instance Method Details
#prompt(system: nil, call: nil, text: nil, stream: nil, success: nil, params: {}, if: nil, unless: nil, until: nil) ⇒ Object
Adds a prompt to the list of prompts. At minimum, provide a ‘text` or `call` parameter.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/raix/prompt_declarations.rb', line 25 def prompt(system: nil, call: nil, text: nil, stream: nil, success: nil, params: {}, if: nil, unless: nil, until: nil) name = Digest::SHA256.hexdigest(text.inspect)[0..7] prompts << OpenStruct.new({ name:, system:, call:, text:, stream:, success:, if:, unless:, until:, params: }) define_method(name) do |response| return response if success.nil? return send(success, response) if success.is_a?(Symbol) instance_exec(response, &success) end end |
#prompts ⇒ Object
37 38 39 |
# File 'lib/raix/prompt_declarations.rb', line 37 def prompts @prompts ||= [] end |