Class: Rexec::FileService
- Inherits:
-
Object
- Object
- Rexec::FileService
- Defined in:
- lib/rexec/file_service.rb
Overview
Service for file operations in containers.
Instance Method Summary collapse
-
#delete(container_id, path) ⇒ Object
Delete a file or directory.
-
#download(container_id, path) ⇒ String
Download a file.
-
#initialize(client) ⇒ FileService
constructor
A new instance of FileService.
-
#list(container_id, path = "/") ⇒ Array<FileInfo>
List files in a directory.
-
#mkdir(container_id, path) ⇒ Object
Create a directory.
Constructor Details
#initialize(client) ⇒ FileService
Returns a new instance of FileService.
28 29 30 |
# File 'lib/rexec/file_service.rb', line 28 def initialize(client) @client = client end |
Instance Method Details
#delete(container_id, path) ⇒ Object
Delete a file or directory.
66 67 68 69 70 |
# File 'lib/rexec/file_service.rb', line 66 def delete(container_id, path) encoded_path = URI.encode_www_form_component(path) @client.request(:delete, "/api/containers/#{container_id}/files?path=#{encoded_path}") nil end |
#download(container_id, path) ⇒ String
Download a file.
48 49 50 51 |
# File 'lib/rexec/file_service.rb', line 48 def download(container_id, path) encoded_path = URI.encode_www_form_component(path) @client.request_bytes(:get, "/api/containers/#{container_id}/files?path=#{encoded_path}") end |
#list(container_id, path = "/") ⇒ Array<FileInfo>
List files in a directory.
37 38 39 40 41 |
# File 'lib/rexec/file_service.rb', line 37 def list(container_id, path = "/") encoded_path = URI.encode_www_form_component(path) data = @client.request(:get, "/api/containers/#{container_id}/files/list?path=#{encoded_path}") data.map { |f| FileInfo.new(f) } end |
#mkdir(container_id, path) ⇒ Object
Create a directory.
57 58 59 60 |
# File 'lib/rexec/file_service.rb', line 57 def mkdir(container_id, path) @client.request(:post, "/api/containers/#{container_id}/files/mkdir", body: { path: path }) nil end |