Class: Bits::ExecuteContext

Inherits:
Object
  • Object
show all
Defined in:
lib/bits/execute_context.rb

Constant Summary collapse

SUDO =
'sudo'

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ ExecuteContext

Returns a new instance of ExecuteContext.



5
6
7
# File 'lib/bits/execute_context.rb', line 5

def initialize(user)
  @user = user
end

Instance Method Details

#run(args, params = {}) ⇒ Object

Run a command and return a boolean indicating weither exitcode is 0



20
21
22
23
# File 'lib/bits/execute_context.rb', line 20

def run(args, params={})
  params[:ignore_exitcode] = true
  spawn(args, params) == 0
end

#spawn(args, params = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/bits/execute_context.rb', line 9

def spawn(args, params={})
  superuser = params[:superuser] || false

  if superuser and not @user.superuser?
    Bits.spawn [SUDO] + args, params
  else
    Bits.spawn args, params
  end
end