class Libis::Ingester::FileService

Attributes

root[RW]

Public Class Methods

new(_root) click to toggle source

Create File service param [String] root the root folder for the file service

# File lib/libis/ingester/file_service.rb, line 9
def initialize(_root)
  @root = _root
end

Public Instance Methods

del_dir(remote_path) click to toggle source

Delete a directory param [String] remote_path remote directory

# File lib/libis/ingester/file_service.rb, line 48
def del_dir(remote_path)
  FileUtils.rm([abspath(remote_path)])
end
del_file(remote_path) click to toggle source

Delete a file param [String] remote_path remote file path

# File lib/libis/ingester/file_service.rb, line 42
def del_file(remote_path)
  FileUtils.rm([abspath(remote_path)])
end
del_tree(remote_path) click to toggle source

Delete a directory param [String] remote_path remote directory

# File lib/libis/ingester/file_service.rb, line 54
def del_tree(remote_path)
  FileUtils.rmtree [abspath(remote_path)]
end
exist?(remote_path) click to toggle source
# File lib/libis/ingester/file_service.rb, line 58
def exist?(remote_path)
  File.exist? abspath(remote_path)
end
get_file(remote_path, local_path, _mode = :binary) click to toggle source

Download a file param [String] remote_path remote file path param [String] local_path param [Symbol] _mode :binary or :text

# File lib/libis/ingester/file_service.rb, line 26
def get_file(remote_path, local_path, _mode = :binary)
  FileUtils.cp abspath(remote_path), local_path
end
is_file?(remote_path) click to toggle source

Check if remote path is a file (or a directory) param [String] remote_path return [Boolean] true if file, false if directory

# File lib/libis/ingester/file_service.rb, line 65
def is_file?(remote_path)
  File.file? abspath(remote_path)
end
ls(dir) click to toggle source

Get directory listing param [String] dir return [Array<String>]

# File lib/libis/ingester/file_service.rb, line 16
def ls(dir)
  Dir.entries(abspath(dir)).map do |entry|
    entry =~ /^\.+$/ ? nil : File.join(dir, entry)
  end.delete_if { |x| x.nil? }
end
put_file(remote_path, data, _mode = :text) click to toggle source

Upload a file param [String] remote_path remote file path param [Object] data param [Symbol] _mode :binary or :text

# File lib/libis/ingester/file_service.rb, line 34
def put_file(remote_path, data, _mode = :text)
  File.open abspath(remote_path), 'w' do |f|
    f.write(data)
  end
end

Protected Instance Methods

abspath(dir) click to toggle source
# File lib/libis/ingester/file_service.rb, line 73
def abspath(dir)
  File.join(@root, dir)
end
relpath(path) click to toggle source
# File lib/libis/ingester/file_service.rb, line 77
def relpath(path)
  require 'pathname'
  Pathname(path).relative_path_from(Pathname(@root)).to_s
end