Sha256: 00f5e6dbbc7104942666feeb3de6a34c19d019bf483781d2ec98c42dd892e6d8

Contents?: true

Size: 1.8 KB

Versions: 12

Compression:

Stored size: 1.8 KB

Contents

namespace :iqvoc do
  namespace :db do

    desc "Load seeds (task is idempotent)"
    task :seed => :environment do
      Iqvoc::Engine.load_seed
    end

    desc "Load seeds from all engines (db/seed tasks should be idempotent)"
    task :seed_all => :environment do
      engines = Rails.application.railties.select do |e|
        e.config.respond_to?(:paths) &&
          e.config.paths["db/seeds.rb"] &&
          e.config.paths["db/seeds.rb"].existent.any?
      end

      engines.select{|e| e.engine_name !~ /^iqvoc_/}.each do |engine|
        puts "There is a non-iQvoc engine (#{engine.engine_name}) having seeds. These seeds are not necessarily idempotent."
        puts "Do you with to (c)ontinue, (i)gnore it or (a)bort?"
        input = nil
        while input !~ /^[cia]$/
          puts "Please try it again [c, i or a]" if input
          STDOUT.flush
          input = STDIN.gets.chomp.downcase
        end
        case input
        when  "i"
          engines.delete(engine)
        when "c"
          # do nothing
        else
          raise "Aborting"
        end
      end

      files = Rails.application.config.paths["db/seeds.rb"].existent +
        engines.map { |e| e.config.paths["db/seeds.rb"].existent }.flatten.compact

      puts "Loading seeds from: " + files.join(", ")
      files.each do |file|
        load(file)
      end
    end

    # invokes the given task for all the namespaces provided as well as for the
    # current application
    # e.g. `invoke_engine_tasks("db:migrate", ["foo", "bar"])` is equivalent to
    # `rake foo:db:migrate bar:db:migrate db:migrate`
    def Iqvoc.invoke_engine_tasks(task_name, engines)
      tasks = engines.map { |engine| "#{engine}:#{task_name}" }
      tasks << task_name
      tasks.each do |task|
        Rake::Task[task].invoke
      end
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
iqvoc-4.10.0 lib/engine_tasks/db.rake
iqvoc-4.9.0 lib/engine_tasks/db.rake
iqvoc-4.8.2 lib/engine_tasks/db.rake
iqvoc-4.8.1 lib/engine_tasks/db.rake
iqvoc-4.8.0 lib/engine_tasks/db.rake
iqvoc-4.7.0 lib/engine_tasks/db.rake
iqvoc-4.6.1 lib/engine_tasks/db.rake
iqvoc-4.5.2 lib/engine_tasks/db.rake
iqvoc-4.6.0 lib/engine_tasks/db.rake
iqvoc-4.5.1 lib/engine_tasks/db.rake
iqvoc-4.5.0 lib/engine_tasks/db.rake
iqvoc-4.4.0 lib/engine_tasks/db.rake