Class: Babushka::Task
- Includes:
- LogHelpers, PathHelpers, ShellHelpers
- Defined in:
- lib/babushka/task.rb
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#current_dep ⇒ Object
readonly
Returns the value of attribute current_dep.
-
#persistent_log ⇒ Object
readonly
Returns the value of attribute persistent_log.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ Task
constructor
A new instance of Task.
- #log_path_for(dep) ⇒ Object
- #open_log!(mode = 'a') ⇒ Object
- #opt(name) ⇒ Object
- #process(dep_names, with_args, cmd) ⇒ Object
- #process_dep(dep_name, with_args) ⇒ Object
- #running? ⇒ Boolean
Methods included from ShellHelpers
cmd_dir, current_username, log_shell, login_shell, raw_shell, shell, shell!, shell?, shell_cmd, sudo, which
Methods included from LogHelpers
debug, deprecated!, log, log_block, log_error, log_ok, log_stderr, log_warn, removed!
Methods included from PathHelpers
cd, in_build_dir, in_download_dir
Constructor Details
#initialize ⇒ Task
Returns a new instance of Task.
9 10 11 |
# File 'lib/babushka/task.rb', line 9 def initialize clear end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
7 8 9 |
# File 'lib/babushka/task.rb', line 7 def cmd @cmd end |
#current_dep ⇒ Object (readonly)
Returns the value of attribute current_dep.
7 8 9 |
# File 'lib/babushka/task.rb', line 7 def current_dep @current_dep end |
#persistent_log ⇒ Object (readonly)
Returns the value of attribute persistent_log.
7 8 9 |
# File 'lib/babushka/task.rb', line 7 def persistent_log @persistent_log end |
Instance Method Details
#clear ⇒ Object
13 14 15 16 |
# File 'lib/babushka/task.rb', line 13 def clear @cmd = nil @running = false end |
#log_path_for(dep) ⇒ Object
48 49 50 |
# File 'lib/babushka/task.rb', line 48 def log_path_for dep log_prefix / dep.contextual_name end |
#open_log!(mode = 'a') ⇒ Object
52 53 54 55 56 |
# File 'lib/babushka/task.rb', line 52 def open_log! mode = 'a' log_prefix.mkdir @persistent_log.close unless @persistent_log.nil? # If the log was already open, close it. @persistent_log = log_path_for(current_dep).open(mode).tap {|f| f.sync = true } end |
#opt(name) ⇒ Object
40 41 42 |
# File 'lib/babushka/task.rb', line 40 def opt name cmd.opts[name] unless cmd.nil? end |
#process(dep_names, with_args, cmd) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/babushka/task.rb', line 18 def process dep_names, with_args, cmd raise "A task is already running." if running? @cmd = cmd @running = true dep_names.all? {|dep_name| process_dep(dep_name, with_args) } rescue SourceLoadError => e Babushka::Logging.log_exception(e) ensure clear end |
#process_dep(dep_name, with_args) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/babushka/task.rb', line 29 def process_dep dep_name, with_args Base.sources.find_or_suggest(dep_name) do |dep| @current_dep = dep with_logging { dep.with(task_args_for(dep, with_args)).process(!opt(:dry_run)) }.tap { @current_dep = nil } end end |
#running? ⇒ Boolean
44 45 46 |
# File 'lib/babushka/task.rb', line 44 def running? @running end |