Sha256: 7a9b970f35ab2a4bbb662d49fbb7c57cf9f68ae33fc86e29dc21c82106c5ea2f

Contents?: true

Size: 1.75 KB

Versions: 48

Compression:

Stored size: 1.75 KB

Contents

require 'rails'

module Incline::Extensions
  ##
  # Creates a default database configuration to use when config/database.yml is not present.
  module ApplicationConfiguration

    ##
    # Override the +database_configuration+ method to return something in development mode if
    # the +config/database.yml+ file is missing.
    #
    # A warning will be logged if the default configuration is used.  In production mode, an
    # exception will be bubbled up.
    #
    # The default configuration for test and development environments is to use a sqlite
    # database in the db folder using the environment name (eg - db/development.sqlite).
    #
    # The primary purpose of this is to allow +rake+ and +rails+ actions that may not depend on the
    # database configuration or may actually be used to generate the configuration file.
    def self.included(base) #:nodoc:
      base.class_eval do
        alias :incline_appconfig_original_database_configuration :database_configuration

        def database_configuration
          begin
            incline_appconfig_original_database_configuration
          rescue
            raise unless $!.inspect.include?('No such file -') && (!Rails.env.production?)

            default = {
                'adapter' => 'sqlite3',
                'pool' => 5,
                'timeout' => 5000
            }

            Incline::Log::warn "Providing default database configuration for #{Rails.env} environment."

            {
                'test' => default.merge('database' => 'db/test.sqlite'),
                'development' => default.merge('database' => 'db/development.sqlite')
            }
          end
        end
      end
    end

  end
end

Rails::Application::Configuration.include Incline::Extensions::ApplicationConfiguration

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
incline-0.3.14 lib/incline/extensions/application_configuration.rb
incline-0.3.13 lib/incline/extensions/application_configuration.rb
incline-0.3.12 lib/incline/extensions/application_configuration.rb
incline-0.3.11 lib/incline/extensions/application_configuration.rb
incline-0.3.10 lib/incline/extensions/application_configuration.rb
incline-0.3.9 lib/incline/extensions/application_configuration.rb
incline-0.3.8 lib/incline/extensions/application_configuration.rb
incline-0.3.7 lib/incline/extensions/application_configuration.rb
incline-0.3.6 lib/incline/extensions/application_configuration.rb
incline-0.3.5 lib/incline/extensions/application_configuration.rb
incline-0.3.4 lib/incline/extensions/application_configuration.rb
incline-0.3.3 lib/incline/extensions/application_configuration.rb
incline-0.3.2 lib/incline/extensions/application_configuration.rb
incline-0.3.1 lib/incline/extensions/application_configuration.rb
incline-0.3.0 lib/incline/extensions/application_configuration.rb
incline-0.2.36 lib/incline/extensions/application_configuration.rb
incline-0.2.35 lib/incline/extensions/application_configuration.rb
incline-0.2.34 lib/incline/extensions/application_configuration.rb
incline-0.2.28 lib/incline/extensions/application_configuration.rb
incline-0.2.27 lib/incline/extensions/application_configuration.rb