Sha256: f61ee3eb8d10259aa8d4f7cee97938cf9da07d576f24a248860c10713a88dceb

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 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
  task spec: 'spec:find_and_specs'

  namespace :spec do
    desc "Finds Specifications"
    task :find_and_specs do
      RSpec::Core::RakeTask.new('spec') do |t|
        t.pattern = "spec/[^_]**/[^_]*_spec.rb"
      end
    end

    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.5.3 lib/rake_ext.rb