Class: Orca::ExecutionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/orca/execution_context.rb

Direct Known Subclasses

MockExecutionContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, log) ⇒ ExecutionContext

Returns a new instance of ExecutionContext.



6
7
8
9
10
# File 'lib/orca/execution_context.rb', line 6

def initialize(node, log)
  @node = node
  @log = log
  @node.log_to(@log)
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



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

def node
  @node
end

Instance Method Details

#apply(blk) ⇒ Object



12
13
14
# File 'lib/orca/execution_context.rb', line 12

def apply(blk)
  instance_eval(&blk)
end

#binary_exists?(binary) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/orca/execution_context.rb', line 76

def binary_exists?(binary)
  run("which #{binary}") =~ /\/#{binary}/
end

#download(from, to) ⇒ Object



40
41
42
# File 'lib/orca/execution_context.rb', line 40

def download(from, to)
  @node.download(from, to)
end

#local(path) ⇒ Object



44
45
46
# File 'lib/orca/execution_context.rb', line 44

def local(path)
  Orca::LocalFile.new(path)
end

#log(msg = nil) ⇒ Object



27
28
29
30
# File 'lib/orca/execution_context.rb', line 27

def log(msg=nil)
  @log.log(msg) if msg
  @log
end

#remote(path) ⇒ Object



60
61
62
# File 'lib/orca/execution_context.rb', line 60

def remote(path)
  Orca::RemoteFile.new(self, path)
end

#remove(path) ⇒ Object



48
49
50
# File 'lib/orca/execution_context.rb', line 48

def remove(path)
  @node.remove(path)
end

#run(cmd, opts = {}) ⇒ Object



23
24
25
# File 'lib/orca/execution_context.rb', line 23

def run(cmd, opts={})
  @node.execute(cmd, opts)
end

#run_local(cmd) ⇒ Object



16
17
18
19
20
21
# File 'lib/orca/execution_context.rb', line 16

def run_local(cmd)
  @log.local(cmd)
  stdout, stderr, status = Open3.capture3(cmd)
  @log.stdout(stdout)
  @log.stderr(stderr)
end

#setstat(path, opts) ⇒ Object



56
57
58
# File 'lib/orca/execution_context.rb', line 56

def setstat(path, opts)
  @node.setstat(path, opts)
end

#stat(path) ⇒ Object



52
53
54
# File 'lib/orca/execution_context.rb', line 52

def stat(path)
  @node.stat(path)
end

#sudo(cmd, opts = {}) ⇒ Object



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

def sudo(cmd, opts={})
  @node.sudo(cmd, opts)
end

#template(path) ⇒ Object



64
65
66
# File 'lib/orca/execution_context.rb', line 64

def template(path)
  Orca::Template.new(@node, path)
end

#trigger(action_ref, *args) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/orca/execution_context.rb', line 68

def trigger(action_ref, *args)
  pkg_name, action_name = *action_ref.split(':', 2)
  pkg = Orca::PackageIndex.default.get(pkg_name)
  action = pkg.actions[action_name]
  raise Orca::MissingActionError.new(action_ref) unless action
  instance_exec(*args, &action)
end

#upload(from, to) ⇒ Object



36
37
38
# File 'lib/orca/execution_context.rb', line 36

def upload(from, to)
  @node.upload(from, to)
end