Class: CommandExecutor

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/vpn_routing_mac/command_executor.rb

Defined Under Namespace

Classes: CommandFailed

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#verboseObject

Returns the value of attribute verbose.



5
6
7
# File 'lib/vpn_routing_mac/command_executor.rb', line 5

def verbose
  @verbose
end

Instance Method Details

#execute!(command, verbose: @verbose, exception: true) ⇒ Object

execute command

Parameters:

  • command (String)

    execute command

  • verbose (Boolean) (defaults to: @verbose)

    log for the command

  • exception (Boolean) (defaults to: true)

    raise exception if the command failed

Raises:



18
19
20
21
22
23
24
25
# File 'lib/vpn_routing_mac/command_executor.rb', line 18

def execute!(command, verbose: @verbose, exception: true)
  puts "cmd: #{command}" if verbose
  ret, err, status = Open3.capture3(command)

  raise CommandFailed.new(err) if exception && !status.success?

  ret
end

#instanceObject



9
10
11
# File 'lib/vpn_routing_mac/command_executor.rb', line 9

def instance
  @verbose = false
end