Class: Obfusc::EncryptorCommandBase

Inherits:
Object
  • Object
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.

Direct Known Subclasses

CryptCommand, DecryptCommand

Constant Summary collapse

COMMANDS =
%w[move copy].freeze
CURRENT_DIR =
'./'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, from, to) ⇒ EncryptorCommandBase

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

#copyObject



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

#filesObject

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/obfusc/commands/concerns/encryptor_command_base.rb', line 28

def files
  raise NotImplementedError
end

#moveObject



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_usageObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/obfusc/commands/concerns/encryptor_command_base.rb', line 24

def show_usage
  raise NotImplementedError
end