Class: RCrewAI::Tools::FileWriter
- Defined in:
- lib/rcrewai/tools/file_writer.rb
Constant Summary
Constants included from RCrewAI::ToolSchema
Instance Method Summary collapse
- #execute(**params) ⇒ Object
-
#initialize(**options) ⇒ FileWriter
constructor
A new instance of FileWriter.
Methods inherited from Base
available_tools, create_tool, #description, #execute_with_validation, #json_schema, list_available_tools, #name, #validate_params!
Methods included from RCrewAI::ToolSchema
#description, extended, #json_schema, #param, #params, #tool_name
Constructor Details
#initialize(**options) ⇒ FileWriter
Returns a new instance of FileWriter.
19 20 21 22 23 24 |
# File 'lib/rcrewai/tools/file_writer.rb', line 19 def initialize(**) super() @max_file_size = .fetch(:max_file_size, 10_000_000) # 10MB @allowed_extensions = .fetch(:allowed_extensions, %w[.txt .md .json .yaml .yml .csv .log]) @create_directories = .fetch(:create_directories, true) end |
Instance Method Details
#execute(**params) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rcrewai/tools/file_writer.rb', line 26 def execute(**params) validate_params!(params, required: %i[file_path content], optional: %i[mode encoding]) file_path = params[:file_path] content = params[:content] mode = params[:mode] || 'w' # 'w' for write, 'a' for append encoding = params[:encoding] || 'utf-8' begin write_file(file_path, content, mode, encoding) rescue StandardError => e "File write failed: #{e.}" end end |