Module: Genie::SandboxedFileTool
- Included in:
- AppendToFile, InsertIntoFile, ListFiles, ReadFile, RenameFile, ReplaceLinesInFile, WriteFile
- Defined in:
- lib/genie/sandboxed_file_tool.rb
Instance Method Summary collapse
- #enforce_sandbox!(filepath) ⇒ Object
- #initialize(base_path:) ⇒ Object
- #within_sandbox?(filepath) ⇒ Boolean
Instance Method Details
#enforce_sandbox!(filepath) ⇒ Object
15 16 17 18 19 |
# File 'lib/genie/sandboxed_file_tool.rb', line 15 def enforce_sandbox!(filepath) unless within_sandbox?(filepath) raise ArgumentError, "File not allowed: #{filepath}. Must be within base path: #{@base_path}" end end |
#initialize(base_path:) ⇒ Object
5 6 7 8 |
# File 'lib/genie/sandboxed_file_tool.rb', line 5 def initialize(base_path:) @base_path = base_path @base_path.freeze end |
#within_sandbox?(filepath) ⇒ Boolean
10 11 12 13 |
# File 'lib/genie/sandboxed_file_tool.rb', line 10 def within_sandbox?(filepath) filepath = File.(filepath) filepath.start_with?(@base_path) end |