Class: Obfusc::EncryptorCommandBase
- Inherits:
-
Object
- Object
- Obfusc::EncryptorCommandBase
show all
- Defined in:
- lib/obfusc/commands/concerns/encryptor_command_base.rb
Overview
Commom methods shared between CryptCommand and DecryptCommand models. Children models only overwrite ‘show_usage` and files.
Constant Summary
collapse
- COMMANDS =
%w[move copy].freeze
- CURRENT_DIR =
'./'.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of EncryptorCommandBase.
10
11
12
13
14
15
|
# File 'lib/obfusc/commands/concerns/encryptor_command_base.rb', line 10
def initialize(config, from, to)
@config = config
@from = from || CURRENT_DIR
@to = to || CURRENT_DIR
end
|
Class Method Details
.call(config, *args) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/obfusc/commands/concerns/encryptor_command_base.rb', line 17
def self.call(config, *args)
command, from, to = args
model = new(config, from, to)
command = 'show_usage' unless COMMANDS.include?(command)
model.public_send(command)
end
|
Instance Method Details
#copy ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/obfusc/commands/concerns/encryptor_command_base.rb', line 43
def copy
files.each_with_index do |(from, to), index|
create_target_base_directory if index.zero?
create_directory_from_file(to)
@config.log("cp #{from} #{to}")
@config.dry_run do
FileUtils.cp(from, to, verbose: @config.verbose?)
end
end.size
end
|
#files ⇒ Object
28
29
30
|
# File 'lib/obfusc/commands/concerns/encryptor_command_base.rb', line 28
def files
raise NotImplementedError
end
|
#move ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/obfusc/commands/concerns/encryptor_command_base.rb', line 32
def move
files.each_with_index do |(from, to), index|
create_target_base_directory if index.zero?
create_directory_from_file(to)
@config.log("mv #{from} #{to}")
@config.dry_run do
FileUtils.mv(from, to, verbose: @config.verbose?)
end
end.size
end
|
#show_usage ⇒ Object
24
25
26
|
# File 'lib/obfusc/commands/concerns/encryptor_command_base.rb', line 24
def show_usage
raise NotImplementedError
end
|