Class: Ask::Rails::Tools::ReadFile

Inherits:
Ask::Rails::Tool show all
Defined in:
lib/ask/rails/tools/read_file.rb

Instance Method Summary collapse

Methods inherited from Ask::Rails::Tool

#rails_root

Instance Method Details

#execute(path:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/ask/rails/tools/read_file.rb', line 11

def execute(path:)
  full_path = rails_root.join(path)
  return Ask::Result.error(message: "File not found: #{path}") unless full_path.exist?

  content = full_path.read
  Ask::Result.success(
    data: { path: path, content: content, size: content.length },
    metadata: { path: path, size: content.length }
  )
end