Class: OxAiWorkers::Tool::Eval
- Inherits:
-
Object
- Object
- OxAiWorkers::Tool::Eval
- Includes:
- DependencyHelper, LoadI18n, OxAiWorkers::ToolDefinition
- Defined in:
- lib/oxaiworkers/tool/eval.rb
Instance Attribute Summary collapse
-
#current_dir ⇒ Object
Returns the value of attribute current_dir.
Attributes included from LoadI18n
Attributes included from OxAiWorkers::ToolDefinition
Instance Method Summary collapse
-
#initialize(only: nil, current_dir: nil) ⇒ Eval
constructor
A new instance of Eval.
- #ruby(input:) ⇒ Object
- #sh(input:) ⇒ Object
Methods included from LoadI18n
Methods included from DependencyHelper
Methods included from OxAiWorkers::ToolDefinition
#define_function, #full_function_name, #function_schemas, #init_white_list_with, #tool_name
Constructor Details
#initialize(only: nil, current_dir: nil) ⇒ Eval
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/oxaiworkers/tool/eval.rb', line 14 def initialize(only: nil, current_dir: nil) store_locale init_white_list_with only @current_dir = current_dir define_function :ruby, description: I18n.t('oxaiworkers.tool.eval.ruby.description') do property :input, type: 'string', description: I18n.t('oxaiworkers.tool.eval.ruby.input'), required: true end define_function :sh, description: I18n.t('oxaiworkers.tool.eval.sh.description') do property :input, type: 'string', description: I18n.t('oxaiworkers.tool.eval.sh.input'), required: true end end |
Instance Attribute Details
#current_dir ⇒ Object
Returns the value of attribute current_dir.
12 13 14 |
# File 'lib/oxaiworkers/tool/eval.rb', line 12 def current_dir @current_dir end |
Instance Method Details
#ruby(input:) ⇒ Object
29 30 31 32 |
# File 'lib/oxaiworkers/tool/eval.rb', line 29 def ruby(input:) OxAiWorkers.logger.info("Executing ruby: \"#{input}\"", for: self.class) execute_in_directory { eval(input) } end |
#sh(input:) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/oxaiworkers/tool/eval.rb', line 34 def sh(input:) OxAiWorkers.logger.info("Executing sh: \"#{input}\"", for: self.class) execute_in_directory do stdout_and_stderr_s, status = Open3.capture2e(input) stdout_and_stderr_s.present? ? stdout_and_stderr_s : status.to_s end end |