Class: ConvenientService::Examples::Standard::Gemfile::Services::PrintShellCommand

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command:, skip: false, out: $stdout) ⇒ PrintShellCommand

Returns a new instance of PrintShellCommand.



18
19
20
21
22
# File 'lib/convenient_service/examples/standard/gemfile/services/print_shell_command.rb', line 18

def initialize(command:, skip: false, out: $stdout)
  @command = command
  @skip = skip
  @out = out
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



16
17
18
# File 'lib/convenient_service/examples/standard/gemfile/services/print_shell_command.rb', line 16

def command
  @command
end

#outObject (readonly)

Returns the value of attribute out.



16
17
18
# File 'lib/convenient_service/examples/standard/gemfile/services/print_shell_command.rb', line 16

def out
  @out
end

#skipObject (readonly)

Returns the value of attribute skip.



16
17
18
# File 'lib/convenient_service/examples/standard/gemfile/services/print_shell_command.rb', line 16

def skip
  @skip
end

Instance Method Details

#fallback_resultObject



37
38
39
# File 'lib/convenient_service/examples/standard/gemfile/services/print_shell_command.rb', line 37

def fallback_result
  success
end

#resultObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/convenient_service/examples/standard/gemfile/services/print_shell_command.rb', line 24

def result
  return error("Command is `nil`") if command.nil?
  return error("Command is empty?") if command.empty?

  return failure("Printing of shell command `#{command}` is skipped") if skip

  out.puts

  out.puts ::Paint["$ #{command}", :blue, :bold]

  success
end