Class: Rails::Mongoid::Railtie

Inherits:
Railtie
  • Object
show all
Defined in:
lib/mongoid/railtie.rb

Overview

Hooks Mongoid into Rails 3 and higher.

Since:

  • 2.0.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generatorSymbol

Determine which generator to use. app_generators was introduced after 3.0.0.

Examples:

Get the generators method.

railtie.generators

Returns:

  • (Symbol)

    The method name to use.

Since:

  • 2.0.0.rc.4



25
26
27
# File 'lib/mongoid/railtie.rb', line 25

def self.generator
  config.respond_to?(:app_generators) ? :app_generators : :generators
end

.rescue_responsesObject

Mapping of rescued exceptions to HTTP responses

@ return [Hash] rescued responses

Examples:

railtie.rescue_responses

Since:

  • 2.4.3



37
38
39
40
41
42
# File 'lib/mongoid/railtie.rb', line 37

def self.rescue_responses
  {
    "Mongoid::Errors::DocumentNotFound" => :not_found,
    "Mongoid::Errors::Validations" => 422
  }
end

Instance Method Details

#handle_configuration_error(e) ⇒ Object

Rails runs all initializers first before getting into any generator code, so we have no way in the intitializer to know if we are generating a mongoid.yml. So instead of failing, we catch all the errors and print them out.

Since:

  • 3.0.0



142
143
144
145
# File 'lib/mongoid/railtie.rb', line 142

def handle_configuration_error(e)
  puts "There is a configuration error with the current mongoid.yml."
  puts e.message
end