Class: PrepKit::Context
- Inherits:
-
Object
- Object
- PrepKit::Context
- Defined in:
- lib/prep_kit/context.rb
Instance Method Summary collapse
- #call(name) ⇒ 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 7 |
# File 'lib/prep_kit/context.rb', line 3 def initialize(host, user, = {}) @vars = {} @env = environment(host, user, ) @memoized = {} end |
Instance Method Details
#call(name) ⇒ Object
19 20 21 22 23 |
# File 'lib/prep_kit/context.rb', line 19 def call(name) raise NotFoundError, name unless Proc === (block = @vars[name]) Task.new(self).action &block end |
#load(filename) ⇒ Object
15 16 17 |
# File 'lib/prep_kit/context.rb', line 15 def load(filename) instance_eval open(filename, &:read), filename end |
#sh(command) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/prep_kit/context.rb', line 25 def sh(command) PrepKit.logger.info "sh: ".bold + command.underline status = @memoized.fetch(command) do @memoized[command] = :skip @env.exec!(command) == 0 ? :success : :failure end raise RuntimeError, command if status == :failure status end |
#task(name, &block) ⇒ Object
9 10 11 12 13 |
# File 'lib/prep_kit/context.rb', line 9 def task(name, &block) raise AssignError, name if @vars[name] @vars[name] = block end |
#test?(path, option) ⇒ Boolean
39 40 41 |
# File 'lib/prep_kit/context.rb', line 39 def test?(path, option) @env.test?(path, option) == 0 end |