class Crew::Context
Attributes
adapter_name[RW]
hints[R]
home[R]
name[R]
opts[RW]
source[RW]
Public Class Methods
new(home, name, file = nil, &blk)
click to toggle source
# File lib/crew/context.rb, line 42 def initialize(home, name, file = nil, &blk) @home = home @name = name @hints = Set.new @shell_count = 0 load(file, &blk) end
Public Instance Methods
enter_sudo_password()
click to toggle source
# File lib/crew/context.rb, line 58 def enter_sudo_password unless defined?(@sudo_password) puts "Getting your sudo password (just this once):" @sudo_password = ENV['SUDO_PASSWORD'] || STDIN.noecho(&:gets).chomp end nil end
hint(h)
click to toggle source
# File lib/crew/context.rb, line 107 def hint(h) @hints << h.to_s end
list() { |task| ... }
click to toggle source
# File lib/crew/context.rb, line 117 def list @home.each_task do |task| yield task end end
load(file = nil, &blk)
click to toggle source
# File lib/crew/context.rb, line 50 def load(file = nil, &blk) DSL.new(self).load(file, &blk) end
logger()
click to toggle source
# File lib/crew/context.rb, line 54 def logger @home.logger end
register()
click to toggle source
# File lib/crew/context.rb, line 127 def register @started ||= begin start true end end
run(name, *hints, &blk)
click to toggle source
# File lib/crew/context.rb, line 66 def run(name, *hints, &blk) with_callbacks do task = Task.new(@home, name) { run &blk } task.default_hints = hints task.run! end end
run_callbacks(type)
click to toggle source
# File lib/crew/context.rb, line 93 def run_callbacks(type) home.callbacks[type].each do |before| run before.source_location.join(':'), &before end end
sh(cmd, opts = {})
click to toggle source
# File lib/crew/context.rb, line 111 def sh(cmd, opts = {}) out, err, code = sh_with_code(cmd, opts) assert code.zero?, "Command `#{cmd}' with out: #{out.inspect} err: #{err.inspect} code=#{code}" out end
start()
click to toggle source
# File lib/crew/context.rb, line 134 def start end
start_shell()
click to toggle source
# File lib/crew/context.rb, line 99 def start_shell run_callbacks(:before) end
stop_shell()
click to toggle source
# File lib/crew/context.rb, line 103 def stop_shell run_callbacks(:after) end
task(name)
click to toggle source
# File lib/crew/context.rb, line 123 def task(name) @home.find_and_add_task(name) end
with_callbacks() { || ... }
click to toggle source
# File lib/crew/context.rb, line 74 def with_callbacks out = nil begin @shell_count += 1 if @shell_count == 1 logger.context @name do start_shell out = yield end else out = yield end ensure @shell_count -= 1 stop_shell if @shell_count == 0 end out end