Sha256: 970f787264e25fb471a2b781255755b29b978fab42b58512c9ad301804d9f726

Contents?: true

Size: 862 Bytes

Versions: 20

Compression:

Stored size: 862 Bytes

Contents

require 'rake'

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

  task :populate => :environment do
    populators.each do |populator|
      if defined?(Rails)
        require "#{Rails.root}/db/populate/#{populator}"
        Kernel.const_get(populator.split('_').collect(&:capitalize).join).run
      else
        Kernel.const_get(populator).run
      end
    end
  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
    defined?(Rails) ? configuration['populators'] : configuration[:populators]
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
smilodon-0.3.10 lib/tasks/populate.rake
smilodon-0.3.9 lib/tasks/populate.rake
smilodon-0.3.8 lib/tasks/populate.rake
smilodon-0.3.7 lib/tasks/populate.rake
smilodon-0.3.6 lib/tasks/populate.rake
smilodon-0.0.2 lib/tasks/populate.rake
smilodon-0.0.1 lib/tasks/populate.rake
smilodon-0.3.5 lib/tasks/populate.rake
smilodon-0.3.4 lib/tasks/populate.rake
smilodon-0.3.3 lib/tasks/populate.rake
smilodon-0.3.2 lib/tasks/populate.rake
smilodon-0.3.1 lib/tasks/populate.rake
smilodon-0.3.0 lib/tasks/populate.rake
smilodon-0.2.8 lib/tasks/populate.rake
smilodon-0.2.7 lib/tasks/populate.rake
smilodon-0.2.6 lib/tasks/populate.rake
smilodon-0.2.5 lib/tasks/populate.rake
smilodon-0.2.4 lib/tasks/populate.rake
smilodon-0.2.3 lib/tasks/populate.rake
smilodon-0.2.2 lib/tasks/populate.rake