Module: Rails::ActivePStore

Extended by:
ActivePStore
Included in:
ActivePStore
Defined in:
lib/rails/active_pstore.rb,
lib/active_pstore/railtie.rb

Defined Under Namespace

Classes: Railtie

Instance Method Summary collapse

Instance Method Details

#load_models(app) ⇒ Object

Use the application configuration to get every model and require it, so that indexing and inheritance work in both development and production with the same results.

Examples:

Load all the application models.

Rails::Mongoid.load_models(app)

Parameters:

  • app (Application)

    The rails application.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rails/active_pstore.rb', line 13

def load_models(app)
  app.config.paths['app/models'].expanded.each do |path|
    preload = ::ActivePStore.preload_models
    if preload.resizable?
      files = preload.map {|model| "#{path}/#{model.underscore}.rb" }
    else
      files = Dir.glob("#{path}/**/*.rb")
    end

    files.sort.each do |file|
      load_model(file.gsub("#{path}/" , "").gsub(".rb", ""))
    end
  end
end

#preload_models(app) ⇒ Object

Conditionally calls ‘Rails::Mongoid.load_models(app)` if the `::Mongoid.preload_models` is `true`.

Parameters:

  • app (Application)

    The rails application.



32
33
34
# File 'lib/rails/active_pstore.rb', line 32

def preload_models(app)
  load_models(app) if ::ActivePStore.preload_models
end