Class: Makit::IO::FileSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/makit/io/filesystem.rb

Instance Method Summary collapse

Constructor Details

#initializeFileSystem

Returns a new instance of FileSystem.



8
9
10
# File 'lib/makit/io/filesystem.rb', line 8

def initialize
  @service = FileSystemServiceImpl.new
end

Instance Method Details

#create_directory(path) ⇒ Object

Create a directory



79
80
81
82
# File 'lib/makit/io/filesystem.rb', line 79

def create_directory(path)
  request = { path: path }
  @service.create_directory(request)
end

#delete_directory(path) ⇒ Object

Delete a directory



85
86
87
88
# File 'lib/makit/io/filesystem.rb', line 85

def delete_directory(path)
  request = { path: path }
  @service.delete_directory(request)
end

#delete_file(path) ⇒ Object

Delete a file by path



51
52
53
54
# File 'lib/makit/io/filesystem.rb', line 51

def delete_file(path)
  request = { path: path }
  @service.delete_file(request)
end

#download(path) ⇒ Object

Download a file in chunks



105
106
107
108
# File 'lib/makit/io/filesystem.rb', line 105

def download(path)
  request = { path: path }
  @service.download(request)
end

#get_file(path, include_metadata: true, include_content: true) ⇒ Object

Get a single file’s content and/or metadata



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/makit/io/filesystem.rb', line 13

def get_file(path, include_metadata: true, include_content: true)
  request = {
    path: path,
    include_metadata: ,
    include_content: include_content
  }
  
  result = @service.get_file(request)
  
  if result.respond_to?(:file)
    # gRPC mode
    result.file
  else
    # Fallback mode
    result[:file]
  end
end

#list_files(directory, recursive: false, pattern: nil, respect_gitignore: false, include_metadata: true, include_content: false) ⇒ Object

List files in a directory according to query flags



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/makit/io/filesystem.rb', line 57

def list_files(directory, recursive: false, pattern: nil, respect_gitignore: false, include_metadata: true, include_content: false)
  request = {
    directory: directory,
    recursive: recursive,
    pattern: pattern,
    respect_gitignore: respect_gitignore,
    include_metadata: ,
    include_content: include_content
  }
  
  result = @service.list_files(request)
  
  if result.respond_to?(:files)
    # gRPC mode
    result.files
  else
    # Fallback mode
    result[:files]
  end
end

#save_file(path, binary_data: nil, text_lines: nil) ⇒ Object

Create or update a file



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/makit/io/filesystem.rb', line 32

def save_file(path, binary_data: nil, text_lines: nil)
  request = {
    path: path,
    binary_data: binary_data,
    text_lines: text_lines
  }
  
  result = @service.save_file(request)
  
  if result.respond_to?(:file)
    # gRPC mode
    result.file
  else
    # Fallback mode
    result[:file]
  end
end

#upload(chunks) ⇒ Object

Upload large files in chunks



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/makit/io/filesystem.rb', line 91

def upload(chunks)
  request = { chunks: chunks }
  result = @service.upload(request)
  
  if result.respond_to?(:file)
    # gRPC mode
    result.file
  else
    # Fallback mode
    result[:file]
  end
end