Module: SystemCommandHelper

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

Constant Summary collapse

VERSION =
"0.2.2"

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



19
20
21
22
23
24
25
26
# File 'lib/system_command_helper.rb', line 19

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

#on_error(&block) ⇒ Object



28
29
30
# File 'lib/system_command_helper.rb', line 28

def on_error(&block)
  @on_error = block
end

#sys(cmd) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/system_command_helper.rb', line 6

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