Module: Grably::Core::TaskEnchancer

Included in:
Rake::Task
Defined in:
lib/grably/core/task/enchancer.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(other_class) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# 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

Instance Method Details

#export(name, export_path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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_executeObject



40
41
42
43
44
45
46
47
# 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_dirObject



36
37
38
# File 'lib/grably/core/task/enchancer.rb', line 36

def task_dir
  File.join(WORKING_DIR, c.profile.join('-'), name)
end