Module: Mongoid::Indexing
- Defined in:
- lib/mongoid/indexing.rb
Class Attribute Summary collapse
-
.logging ⇒ Object
writeonly
Sets the attribute logging.
Class Method Summary collapse
- .create_indexes(models_paths = nil) ⇒ Object
- .load_models_from_paths(*models_paths) ⇒ Object
- .log? ⇒ Boolean
- .log_off! ⇒ Object
- .log_on! ⇒ Object
- .rails_models_paths ⇒ Object
- .remove_indexes(models_paths = nil) ⇒ Object
Class Attribute Details
.logging=(value) ⇒ Object (writeonly)
Sets the attribute logging
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
18 19 20 21 22 23 24 25 |
# File 'lib/mongoid/indexing.rb', line 18 def create_indexes models_paths = nil "creating mongoid indexes..." models_paths = rails_models_paths if models_paths == :rails load_models_from_paths models_paths ::Rails::Mongoid.create_indexes end |
.load_models_from_paths(*models_paths) ⇒ Object
37 38 39 40 41 |
# File 'lib/mongoid/indexing.rb', line 37 def load_models_from_paths *models_paths [models_paths].flatten.compact.each do |path| require "#{path}/**/*.rb" unless path.blank? end end |
.log? ⇒ Boolean
14 15 16 |
# File 'lib/mongoid/indexing.rb', line 14 def log? @logging ||= false 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_paths ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/mongoid/indexing.rb', line 43 def rails_models_paths engines_models_paths = ::Rails.application.railties.engines.map do |engine| engine.paths["app/models"]. end root_models_paths = ::Rails.application.paths["app/models"] engines_models_paths.push(root_models_paths).flatten end |
.remove_indexes(models_paths = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/mongoid/indexing.rb', line 27 def remove_indexes models_paths = nil "removing mongoid indexes..." models_paths = rails_models_paths if models_paths == :rails load_models_from_paths models_paths ::Rails::Mongoid.remove_indexes end |