Class: RailsAiBridge::Services::FileManagementService
- Inherits:
-
RailsAiBridge::Service
- Object
- RailsAiBridge::Service
- RailsAiBridge::Services::FileManagementService
- Defined in:
- lib/rails_ai_bridge/services/file_management_service.rb
Overview
Application service for file system operations confined to an allowed base directory.
All paths are expanded and must lie under Rails.root when Rails is loaded, otherwise under Dir.pwd. This limits read/write/delete to the application tree and returns failures (including SecurityError) as RailsAiBridge::Service::Result instead of raising.
Class Method Summary collapse
-
.call(operation) ⇒ RailsAiBridge::Service::Result
Success or failure with errors.
Instance Method Summary collapse
-
#call(operation) ⇒ RailsAiBridge::Service::Result
Dispatches the file operation after validating +operation+ and (for supported ops) the path.
Methods inherited from RailsAiBridge::Service
Constructor Details
This class inherits a constructor from RailsAiBridge::Service
Class Method Details
.call(operation) ⇒ RailsAiBridge::Service::Result
Returns success or failure with errors.
30 31 32 |
# File 'lib/rails_ai_bridge/services/file_management_service.rb', line 30 def self.call(operation, **) new.call(operation, **) end |
Instance Method Details
#call(operation) ⇒ RailsAiBridge::Service::Result
Dispatches the file operation after validating +operation+ and (for supported ops) the path.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rails_ai_bridge/services/file_management_service.rb', line 41 def call(operation, **) return Service::Result.new(false, errors: ['Operation cannot be nil']) if operation.nil? case operation.to_sym when :write write_file(**) when :read read_file(**) when :delete delete_file(**) when :exist? file_exists?(**) else Service::Result.new(false, errors: ["Unsupported operation: #{operation}"]) end end |