class Shellject::Tasks::Save
Encrypts and saves a file as a shelljection.
Attributes
input_path[R]
save_directory[R]
Public Class Methods
new(save_directory, input_path, name = nil)
click to toggle source
# File lib/shellject/tasks/save.rb, line 10 def initialize(save_directory, input_path, name = nil) @save_directory = save_directory @input_path = input_path @name = name end
Public Instance Methods
call()
click to toggle source
# File lib/shellject/tasks/save.rb, line 16 def call ensure_readable ensure_writable with_files do |from, to| crypto.encrypt from, output: to end end
Private Instance Methods
ensure_readable()
click to toggle source
# File lib/shellject/tasks/save.rb, line 44 def ensure_readable raise ShelljectError, "Cannot read file #{input_path}" unless readable? end
ensure_writable()
click to toggle source
# File lib/shellject/tasks/save.rb, line 35 def ensure_writable FileUtils.mkdir_p(output_path.parent) raise ShelljectError, "Cannot save to #{output_path}" unless writable? end
name()
click to toggle source
# File lib/shellject/tasks/save.rb, line 56 def name @name ||= File.basename(input_path) end
output_path()
click to toggle source
# File lib/shellject/tasks/save.rb, line 52 def output_path @output_path ||= save_directory.path_for name end
readable?()
click to toggle source
# File lib/shellject/tasks/save.rb, line 48 def readable? File.readable? input_path end
with_files() { |from, to| ... }
click to toggle source
# File lib/shellject/tasks/save.rb, line 26 def with_files from = File.open(input_path) to = File.open(output_path, 'wb') yield from, to ensure from&.close to&.close end
writable?()
click to toggle source
# File lib/shellject/tasks/save.rb, line 40 def writable? output_path.parent.writable? end