Class: Koine::Filesystem::Adapters::Local

Inherits:
Base
  • Object
show all
Defined in:
lib/koine/filesystem/adapters/local.rb

Overview

rubocop:disable Lint/UnusedMethodArgument

Instance Method Summary collapse

Methods inherited from Base

#copy, #create_dir, #delete, #delete_dir, #mime_type, #read_and_delete, #read_stream, #rename, #update, #update_stream, #write_stream

Constructor Details

#initialize(root:, path_sanitizer: PathSanitizer.new) ⇒ Local

Returns a new instance of Local.



10
11
12
13
# File 'lib/koine/filesystem/adapters/local.rb', line 10

def initialize(root:, path_sanitizer: PathSanitizer.new)
  @root = root
  @path_sanitizer = path_sanitizer
end

Instance Method Details

#has?(path) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/koine/filesystem/adapters/local.rb', line 25

def has?(path)
  File.exist?(full_path(path))
end

#list(dir = '', recursive: false) ⇒ Object



37
38
39
40
41
# File 'lib/koine/filesystem/adapters/local.rb', line 37

def list(dir = '', recursive: false)
  Dir[create_list_pattern(dir, recursive)].map do |file|
    (file)
  end
end

#read(path) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/koine/filesystem/adapters/local.rb', line 15

def read(path)
  if has?(path)
    file = File.open(full_path(path), 'rb')
    content = file.read
    file.close
    return content
  end
  raise_not_found(path)
end

#size(path) ⇒ Object



43
44
45
# File 'lib/koine/filesystem/adapters/local.rb', line 43

def size(path)
  File.size(full_path(path))
end

#write(path, content, options: {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/koine/filesystem/adapters/local.rb', line 29

def write(path, content, options: {})
  path = full_path(path)
  ensure_target_dir(path)
  File.open(path, 'w') do |f|
    f.write(content)
  end
end