Class: PrepKit::Context
- Inherits:
-
Object
- Object
- PrepKit::Context
- Defined in:
- lib/prep_kit/context.rb
Instance Method Summary collapse
- #call(name) ⇒ Object
- #current_directory ⇒ Object
-
#initialize(host, user, options) ⇒ Context
constructor
A new instance of Context.
- #load(filename) ⇒ Object
- #sh(command) ⇒ Object
- #task(name, &block) ⇒ Object
- #test?(path, option) ⇒ Boolean
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, ) @vars = {} @env = RemoteMarshal.new(host, user, ) end |
Instance Method Details
#call(name) ⇒ Object
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_directory ⇒ Object
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
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
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
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 |