Class: Spud::BuildTools::SpudBuild::RuleContext

Inherits:
Object
  • Object
show all
Defined in:
lib/build_tools/spud/rule_context.rb

Defined Under Namespace

Classes: ShOut

Instance Method Summary collapse

Constructor Details

#initialize(spud, file_context) ⇒ RuleContext

Returns a new instance of RuleContext.



8
9
10
11
12
13
14
# File 'lib/build_tools/spud/rule_context.rb', line 8

def initialize(spud, file_context)
  @spud = spud

  file_context.singleton_methods.each do |method_name|
    define_singleton_method(method_name, &file_context.method(method_name))
  end
end

Instance Method Details

#die(message = nil, code: 1) ⇒ Object

Raises:



56
57
58
59
# File 'lib/build_tools/spud/rule_context.rb', line 56

def die(message = nil, code: 1)
  puts message if message
  raise Error, code
end

#invoke(rule_name, *args, **kwargs) ⇒ Object



52
53
54
# File 'lib/build_tools/spud/rule_context.rb', line 52

def invoke(rule_name, *args, **kwargs)
  @spud.invoke_rule(rule_name.to_s, *args, **kwargs)
end

#sh(*args) ⇒ Object

Raises:



16
17
18
19
# File 'lib/build_tools/spud/rule_context.rb', line 16

def sh(*args)
  out = sh?(*args)
  raise ShellError unless out.status.exitstatus.zero?
end

#sh?(*args) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
# File 'lib/build_tools/spud/rule_context.rb', line 21

def sh?(*args)
  cmd = args.join(' ')
  puts cmd

  out = Spud::Shell.cmd(cmd)
  puts out

  out
end

#shh(*args) ⇒ Object

Raises:



31
32
33
34
# File 'lib/build_tools/spud/rule_context.rb', line 31

def shh(*args)
  out = shh?(*args)
  raise ShellError unless out.status.exitstatus.zero?
end

#shh?(*args) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/build_tools/spud/rule_context.rb', line 36

def shh?(*args)
  out = Spud::Shell.cmd(args.join(' '))
  puts out

  out
end

#shhh(*args) ⇒ Object

Raises:



43
44
45
46
# File 'lib/build_tools/spud/rule_context.rb', line 43

def shhh(*args)
  out = shhh?(*args)
  raise ShellError, out unless out.status.exitstatus.zero?
end

#shhh?(*args) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/build_tools/spud/rule_context.rb', line 48

def shhh?(*args)
  Spud::Shell.cmd(args.join(' '))
end