Class: Tap::Declarations::Context

Inherits:
Object
  • Object
show all
Includes:
Tap::Declarations, Utils
Defined in:
lib/tap/declarations/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

set_env, sh, sh_escape, shellsplit, with_env

Methods included from Tap::Declarations

#baseclass, #declare, #desc, #env, #join, #namespace, #singleton, #task, #work

Constructor Details

#initialize(app, ns = nil) ⇒ Context

Returns a new instance of Context.



9
10
11
12
13
# File 'lib/tap/declarations/context.rb', line 9

def initialize(app, ns=nil)
  @app = app
  initialize_declare
  namespace(ns)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



26
27
28
# File 'lib/tap/declarations/context.rb', line 26

def method_missing(sym, *args, &block)
  app.send(sym, *args, &block)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/tap/declarations/context.rb', line 7

def app
  @app
end

Instance Method Details

#node(num) ⇒ Object



22
23
24
# File 'lib/tap/declarations/context.rb', line 22

def node(num)
  app.get(num.to_s)
end

#sh(*cmd) ⇒ Object

Runs the command with system and raises an error if the command fails.



17
18
19
20
# File 'lib/tap/declarations/context.rb', line 17

def sh(*cmd)
  app.log :sh, cmd.join(' ')
  system(*cmd) or raise "Command failed with status (#{$?.exitstatus}): [#{cmd.join(' ')}]"
end