Sha256: 94152cab431613b0baee1a3ded9c7546ced168881a8f79711717bc6f5b251a3d

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

require 'semver'
require 'rake' 
require 'rake/clean'
include Rake::DSL

require_relative './commands.rb'
require_relative './console.rb'

CLEAN.include("*.gem")

class DevTasks
  
  attr_accessor :version, :commands

  def initialize
    v=SemVer.find
    @version="#{v.major}.#{v.minor}.#{v.patch}"
	about
	@commands=Commands.new
	update_tasks
  end

  def about
    puts Color.green + "dev_tasks " + version + Color.clear
  end

  def execute_task task
    start_time=Time.now
    Console.announce_task_start task
    if(!@commands.has_key?(task))
      puts "no commands discovered for task " + task
    else
      @commands[task].each {|c| @commands.execute_command(c) }
    end
    end_time=Time.now
    elapsed=end_time-start_time
    elapsed_str="[" + "%.0f" %(elapsed) + "s]"
    Console.announce_task_end task, elapsed_str
  end

  def define_task task_name
    if(!Rake::Task.task_defined?(task_name))
      ruby="desc '#{task_name} task';task :#{task_name} do;DEV_TASKS.execute_task '#{task_name}';end"
	  eval(ruby)
	end
  end

  def update_tasks
    dev_task_defaults=Array.new
	@commands.each do |key,array|
	  if(array.length > 0)
	    define_task key
	    dev_task_defaults << key
	  end
	end

	if(!Rake::Task.task_defined?('dev_tasks_default'))
	  tasklist=""
	  dev_task_defaults.each{|t|
	    tasklist = tasklist + "," if tasklist.length > 0
	    tasklist = tasklist + ":" + t
	  }
	  ruby="desc 'dev_tasks_default task';task :dev_tasks_default => [#{tasklist}] do;end"
	  eval(ruby)
	end
  end

end

DEV_TASKS=DevTasks.new

desc 'displays dev_task commands'
task :info do
  puts "DEV_TASKS.commands"
  puts " "
  puts DEV_TASKS.commands.show
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dev_tasks-0.0.8 lib/dev_tasks.rb