Module: SystemCommandHelper

Defined in:
lib/system_command_helper.rb,
lib/system_command_helper/version.rb

Constant Summary collapse

VERSION =
"0.3.0"
@@no_exec =
false
@@quiet =
false
@@on_error =
nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#no_execObject

Returns the value of attribute no_exec.



4
5
6
# File 'lib/system_command_helper.rb', line 4

def no_exec
  @no_exec
end

#quietObject

Returns the value of attribute quiet.



4
5
6
# File 'lib/system_command_helper.rb', line 4

def quiet
  @quiet
end

Instance Method Details

#cap(cmd) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/system_command_helper.rb', line 23

def cap(cmd)
  unless @@quiet
    puts "\e[35m#{Dir.pwd}$\e[0m `#{cmd}`"
  end
  unless @@no_exec
    `#{cmd}`
  end
end

#on_error(&block) ⇒ Object



32
33
34
# File 'lib/system_command_helper.rb', line 32

def on_error(&block)
  @@on_error = block
end

#sys(cmd) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/system_command_helper.rb', line 10

def sys(cmd)
  unless @@quiet
    puts "\e[35m#{Dir.pwd}$\e[0m #{cmd}"
  end
  unless @@no_exec
    result = system cmd
    if !result && @@on_error
      @@on_error.call(cmd, result)
    end
    result
  end
end