Class: ConvenientService::Examples::Standard::V1::Gemfile::Services::RunShellCommand

Inherits:
Object
  • Object
show all
Includes:
Service::Configs::Standard::V1
Defined in:
lib/convenient_service/examples/standard/v1/gemfile/services/run_shell_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config

included

Constructor Details

#initialize(command:, debug: false) ⇒ RunShellCommand

Returns a new instance of RunShellCommand.



25
26
27
28
# File 'lib/convenient_service/examples/standard/v1/gemfile/services/run_shell_command.rb', line 25

def initialize(command:, debug: false)
  @command = command
  @debug = debug
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



17
18
19
# File 'lib/convenient_service/examples/standard/v1/gemfile/services/run_shell_command.rb', line 17

def command
  @command
end

#debugObject (readonly)

Returns the value of attribute debug.



17
18
19
# File 'lib/convenient_service/examples/standard/v1/gemfile/services/run_shell_command.rb', line 17

def debug
  @debug
end

Instance Method Details

#resultObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/convenient_service/examples/standard/v1/gemfile/services/run_shell_command.rb', line 30

def result
  ##
  # NOTE: When the command exit code is 0, `system` return `true`, and `false` otherwise.
  # - https://ruby-doc.org/core-3.1.2/Kernel.html#method-i-system
  # - https://stackoverflow.com/a/37329716/12201472
  #
  if system(command)
    success
  else
    error(message: "#{command} returned non-zero exit code")
  end
end