Class: PrepKit::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/prep_kit/context.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, user, options) ⇒ Context

Returns a new instance of Context.



3
4
5
6
# File 'lib/prep_kit/context.rb', line 3

def initialize(host, user, options)
  @vars = {}
  @env  = RemoteMarshal.new(host, user, options)
end

Instance Method Details

#call(name) ⇒ Object

Raises:



18
19
20
21
22
# File 'lib/prep_kit/context.rb', line 18

def call(name)
  raise NotFoundError, name unless Proc === (block = @vars[name])

  Task.new(self).action &block
end

#current_directoryObject



44
45
46
# File 'lib/prep_kit/context.rb', line 44

def current_directory
  nil
end

#load(filename) ⇒ Object



14
15
16
# File 'lib/prep_kit/context.rb', line 14

def load(filename)
  instance_eval open(filename, &:read), filename
end

#sh(command) ⇒ Object

Raises:

  • (RuntimeError)


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

def sh(command)
  status, output, error = @env.exec!(command)

  raise RuntimeError, error unless status == 0

  output
end

#task(name, &block) ⇒ Object

Raises:



8
9
10
11
12
# File 'lib/prep_kit/context.rb', line 8

def task(name, &block)
  raise AssignError, name if @vars[name]

  @vars[name] = block
end

#test?(path, option) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/prep_kit/context.rb', line 32

def test?(path, option)
  status, *_ = @env.test?(path, option)

  status == 0
end