module Grably::Core::TaskEnchancer

Wraps execute method, to print fancy info about task and its execution.

Public Class Methods

execute(*args) click to toggle source
# File lib/grably/core/task/enchancer.rb, line 11
def execute(*args)
  log_execute
  FileUtils.mkdir_p(task_dir)
  old_execute(*args)
  export(to_s, Grably.export_path) if Grably.export_tasks.include?(to_s)
end
included(other_class) click to toggle source
# File lib/grably/core/task/enchancer.rb, line 7
def included(other_class)
  other_class.class_eval do
    alias_method :old_execute, :execute

    def execute(*args)
      log_execute
      FileUtils.mkdir_p(task_dir)
      old_execute(*args)
      export(to_s, Grably.export_path) if Grably.export_tasks.include?(to_s)
    end
  end
end

Public Instance Methods

export(name, export_path) click to toggle source
# File lib/grably/core/task/enchancer.rb, line 21
def export(name, export_path)
  puts "Exporting task #{name}"
  products = bucket
  # Evacuating files. When task is finished other task execution
  # may begin and all files that should be exported will be
  # spoiled.

  # Replace all ':' with '_'. When task name conatains ':' it
  # means that task declared inside namespace. On Windows we can't
  # create directory with ':' in name
  dir_name = name.tr(':', '_')
  dst = File.join(File.dirname(export_path), dir_name)
  Grably.exports << cp_smart(products, dst)
end
log_execute() click to toggle source
# File lib/grably/core/task/enchancer.rb, line 40
def log_execute
  print "* #{self}".blue.bright
  if Grably.export?
    puts " (#{Dir.pwd}, #{c.profile.join('/').yellow})".white.bright
  else
    puts
  end
end
task_dir() click to toggle source
# File lib/grably/core/task/enchancer.rb, line 36
def task_dir
  File.join(WORKING_DIR, c.profile.join('-'), name)
end