Sha256: e1cac7ca0c38b57057483736a40b762f57dfd529247c7dd72d4509800eec78ab

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

require 'rake'
require 'fileutils'

# 
# Code Coverage
# 
# begin
#   require 'class_loader/tasks'
#   
#   desc "Clean code coverage temporary files"
#   task clean: 'class_loader:clean' do
#     require 'fileutils'
#     FileUtils.rm_r '../*/coverage' if File.exist? '../*/coverage'
#   end  
# rescue LoadError
# end

# 
# Spec
# 
begin
  require 'rspec/core/rake_task'
  task default: :spec

  RSpec::Core::RakeTask.new('spec') do |t|
    t.pattern = "spec/**/[^_]*_spec.rb"
  end
  
  namespace :spec do    
    desc "Run RSpec code exapmples in isolated mode (every spec file in another Ruby process)"
    task :isolated do
      Dir.glob("spec/[^_]**/[^_]*_spec.rb").each do |spec_file|
        Kernel.system "rspec #{spec_file}"
      end
    end
  end
rescue LoadError
  task :default do
    puts "default rake task is :rspec but there's no rspec gem installed, install it first"
  end
end

# 
# before, after and remove task
# 
def before task_name, &block
  $_task_counter ||= {}
  counter = ($_task_counter[task_name] ||= 0)
  before_task_name = "#{task_name}_before_#{counter}"
  
  task before_task_name, &block
  task task_name => before_task_name
  
  $_task_counter[task_name] += 1
end

def after task_name, &block
  task task_name, &block
end

def remove_task(task_name)
  Rake.application.instance_variable_get('@tasks').delete(task_name.to_s)
end
alias :delete_task :remove_task


# 
# project
# 
$_project_dir = (
  caller.find{|line| line =~ /\/Rakefile\:/} || 
  raise("You can include the 'rake_ext' only in Rakefile!")
).sub(/\/Rakefile\:.*/, '')
def project_dir
  $_project_dir
end

def project options = nil  
  if options
    $_project = {}
    options.each{|k, v| $_project[k.to_sym] = v}
    
    $_project[:name] || raise("project name not defined")
    $_project[:official_name] ||= $_project[:name]
    
    require 'rake_ext/project'
  end
  $_project || raise("project not defined!")
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby_ext-0.4.25 lib/rake_ext.rb