Class: KamalBackup::CommandSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/kamal_backup/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv:, env: {}) ⇒ CommandSpec

Returns a new instance of CommandSpec.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
# File 'lib/kamal_backup/command.rb', line 10

def initialize(argv:, env: {})
  @argv = Array(argv).compact.map(&:to_s)
  @env = env.each_with_object({}) do |(key, value), result|
    next if value.nil? || value.to_s.empty?

    result[key.to_s] = value.to_s
  end

  raise ArgumentError, "command argv cannot be empty" if @argv.empty?
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



8
9
10
# File 'lib/kamal_backup/command.rb', line 8

def argv
  @argv
end

#envObject (readonly)

Returns the value of attribute env.



8
9
10
# File 'lib/kamal_backup/command.rb', line 8

def env
  @env
end

Instance Method Details

#display(redactor) ⇒ Object



21
22
23
24
# File 'lib/kamal_backup/command.rb', line 21

def display(redactor)
  env_prefix = env.keys.sort.map { |key| "#{key}=#{redactor.redact_value(key, env[key])}" }
  redactor.redact_string((env_prefix + [argv.shelljoin]).join(" "))
end