Sha256: da91ebfc200f4e8d94654b0db35d4cfe308a97bbad50ba5e938dd9c6bc4d3af4

Contents?: true

Size: 1.49 KB

Versions: 11

Compression:

Stored size: 1.49 KB

Contents

@logger = Logger.new(STDOUT)

#########################################################################
# Determine model class from filename.
#########################################################################
def determine_model(path)
  path =~ /(.*)\/(.*).rb/
  $2.camelize.constantize rescue nil # nil happens
end

#########################################################################
# Return array of all models found in application.
#########################################################################
def all_models()
  models = []
  DrgCms.paths(:forms).each do |path|
    models_dir = File.expand_path("../models", path)
    Dir["#{models_dir}/*.rb"].each do |model_file| 
      model = determine_model(model_file)
      models << model if model and model.respond_to?(:index_specifications)
    end
  end
  models
end

#########################################################################
#
#########################################################################
namespace :drg_cms do
  desc "Create indexes for all mongoid models. Including those in gem plugins."
  task :create_indexes => :environment do
    @logger.info( "MONGOID: Checking indexes.")
    Mongoid::Tasks::Database.create_indexes(all_models)
  end

  desc "Remove undefined indexes for all mongoid models. Including those in gem plugins."
  task :remove_undefined_indexes => :environment do
    @logger.info( "MONGOID: Remove undefined indexes.")
    Mongoid::Tasks::Database.remove_undefined_indexes(all_models)
  end
  
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
drg_cms-0.7.1.1 lib/tasks/database.rake
drg_cms-0.7.0.8 lib/tasks/database.rake
drg_cms-0.7.0.2 lib/tasks/database.rake
drg_cms-0.6.1.11 lib/tasks/database.rake
drg_cms-0.6.1.9 lib/tasks/database.rake
drg_cms-0.6.1.6 lib/tasks/database.rake
drg_cms-0.6.1.5 lib/tasks/database.rake
drg_cms-0.6.1.4 lib/tasks/database.rake
drg_cms-0.6.1.1.1 lib/tasks/database.rake
drg_cms-0.6.1.0 lib/tasks/database.rake
drg_cms-0.6.0.8 lib/tasks/database.rake