Sha256: e19501da1f13d7a1e6683434c84cce08d9f73cba85730de2a93a450c7b4322b6

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module MongoModel
  class Railtie < Rails::Railtie
    config.app_generators.orm :mongo_model, :migration => false

    rake_tasks do
      load "mongomodel/tasks/database.rake"
    end
    
    initializer "mongomodel.logger" do
      MongoModel.logger ||= ::Rails.logger
    end
    
    initializer "mongomodel.rescue_responses" do
      ActionDispatch::ShowExceptions.rescue_responses['MongoModel::DocumentNotFound'] = :not_found
    end
    
    initializer "mongomodel.database_configuration" do |app|
      require 'erb'
      
      config = Rails.root.join("config", "mongomodel.yml")
      
      if File.exists?(config)
        mongomodel_configuration = YAML::load(ERB.new(IO.read(config)).result)
        MongoModel.configuration = mongomodel_configuration[Rails.env]
      end
    end
    
    # Expose database runtime to controller for logging.
    initializer "mongomodel.log_runtime" do |app|
      require "mongomodel/railties/controller_runtime"
      ActiveSupport.on_load(:action_controller) do
        include MongoModel::Railties::ControllerRuntime
      end
    end
    
    initializer "mongomodel.passenger_forking" do |app|
      if defined?(PhusionPassenger)
        PhusionPassenger.on_event(:starting_worker_process) do |forked|
          MongoModel.database.connection.connect if forked
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongomodel-0.3.4 lib/mongomodel/railtie.rb