Module: Mongoid::Indexing

Defined in:
lib/mongoid/indexing.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.logging=(value) ⇒ Object (writeonly)

Sets the attribute logging

Parameters:

  • value

    the value to set the attribute logging to.



4
5
6
# File 'lib/mongoid/indexing.rb', line 4

def logging=(value)
  @logging = value
end

Class Method Details

.create_indexes(models_paths = nil) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
# File 'lib/mongoid/indexing.rb', line 18

def create_indexes models_paths = nil
  models_paths ||= rails_models_paths

  raise ArgumentError, "No model paths for creating mongoid indexes" if models_paths.blank?
  message "CREATE INDEXES: #{models_paths}"

  models_paths.each do |path|
    ::Rails::Mongoid.create_indexes("#{path}/**/*.rb")
  end
end

.log?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/mongoid/indexing.rb', line 14

def log?
  @logging
end

.log_off!Object



10
11
12
# File 'lib/mongoid/indexing.rb', line 10

def log_off!
  @logging = false
end

.log_on!Object



6
7
8
# File 'lib/mongoid/indexing.rb', line 6

def log_on!
  @logging = true
end

.rails_models_pathsObject



40
41
42
43
44
45
46
# File 'lib/mongoid/indexing.rb', line 40

def rails_models_paths
  engines_models_paths = Rails.application.railties.engines.map do |engine|
    engine.paths["app/models"].expanded
  end
  root_models_paths = Rails.application.paths["app/models"]
  engines_models_paths.push(root_models_paths).flatten
end

.remove_indexes(models_paths = nil) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
# File 'lib/mongoid/indexing.rb', line 29

def remove_indexes models_paths = nil
  models_paths ||= rails_models_paths

  raise ArgumentError, "No model paths for creating mongoid indexes" if models_paths.blank?
  message "REMOVING INDEXES: #{models_paths}"

  models_paths.each do |path|
    ::Rails::Mongoid.remove_indexes("#{path}/**/*.rb")
  end
end