Sha256: 0ddcece53516cd05269e548db9eeef05f7e258a7cd53d9a55accefc8ab7cbe85

Contents?: true

Size: 618 Bytes

Versions: 4

Compression:

Stored size: 618 Bytes

Contents

require 'rake'

namespace :db do
  desc 'Runs the populators defined in the configuration file'

  task :populate => :environment do
    populators.each { |populator| Kernel.const_get(populator).run }
  end

  private
  def path
    defined?(Rails) ? "#{Rails.root}/config/populate.yml" : "populate.yml"
  end

  def configuration
    @configuration ||= YAML.load_file(path)
  rescue
    raise Exception, 'Missing configuration file. Add a populate.yml in the project directory or in the config/ directory for rails projects.' unless File.exists?(path)
  end

  def populators
    configuration[:populators]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
db-populator-0.1.8 lib/tasks/populate.rake
db-populator-0.1.6 lib/tasks/populate.rake
db-populator-0.1.5 lib/tasks/populate.rake
db-populator-0.1.4 lib/tasks/populate.rake