Skip to content

Commit

Permalink
Change configuration to clients and not sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jun 3, 2015
1 parent 80edbb6 commit 657650b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ en:
invalid_storage_options:
message: "Invalid options passed to %{klass}.store_in: %{options}."
summary: "The :store_in macro takes only a hash of parameters with
the keys :database, :collection, or :session."
the keys :database, :collection, or :client."
resolution: "Change the options passed to store_in to match the
documented API, and ensure all keys in the options hash are
symbols.\n\n
Expand Down
20 changes: 12 additions & 8 deletions lib/mongoid/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def register_model(klass)
def load_configuration(settings)
configuration = settings.with_indifferent_access
self.options = configuration[:options]
self.sessions = configuration[:sessions]
self.clients = configuration[:clients]
end

# Override the database to use globally.
Expand All @@ -145,19 +145,21 @@ def override_database(name)
Threaded.database_override = name
end

# Override the session to use globally.
# Override the client to use globally.
#
# @example Override the session globally.
# config.override_session(:optional)
# @example Override the client globally.
# config.override_client(:optional)
#
# @param [ String, Symbol ] name The name of the session.
# @param [ String, Symbol ] name The name of the client.
#
# @return [ String, Symbol ] The global override.
#
# @since 3.0.0
def override_session(name)
Threaded.session_override = name ? name.to_s : nil
def override_client(name)
Threaded.client_override = name ? name.to_s : nil
end
alias :override_session :override_client
deprecate :override_session, :override_client, 2015, 12

# Purge all data in all collections, including indexes.
#
Expand Down Expand Up @@ -246,12 +248,14 @@ def running_with_passenger?

private

def sessions=(sessions)
def clients=(sessions)
raise Errors::NoSessionsConfig.new unless sessions
sess = sessions.with_indifferent_access
Validators::Session.validate(sess)
@sessions = sess
sess
end
alias :sessions= :clients=
deprecate :sessions=, :clients=, 2015, 12
end
end
4 changes: 2 additions & 2 deletions lib/mongoid/config/validators/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module Mongoid
module Config
module Validators

# Validator for session specific configuration.
# Validator for client specific configuration.
module Session
extend self

STANDARD = [ :database, :hosts, :username, :password ]

# Validate the session configuration.
# Validate the client configuration.
#
# @example Validate the session config.
# Session.validate({ default: { hosts: [ "localhost:27017" ] }})
Expand Down
13 changes: 5 additions & 8 deletions lib/rails/generators/mongoid/config/templates/mongoid.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
development:
# Configure available database sessions. (required)
sessions:
# Defines the default session. (required)
# Configure available database clients. (required)
clients:
# Defines the default client. (required)
default:
# Defines the name of the default database that Mongoid can connect to.
# (required).
database: <%= database_name || app_name %>_development
# Provides the hosts the default session can connect to. Must be an array
# Provides the hosts the default client can connect to. Must be an array
# of host:port pairs. (required)
hosts:
- localhost:27017
Expand Down Expand Up @@ -110,9 +110,6 @@ development:
# inheritance. (default: false)
# preload_models: false

# Protect id and type from mass assignment. (default: true)
# protect_sensitive_fields: true

# Raise an error when performing a #find and the document is not found.
# (default: true)
# raise_not_found_error: true
Expand All @@ -127,7 +124,7 @@ development:
# Ensure all times are UTC in the app side. (default: false)
# use_utc: false
test:
sessions:
clients:
default:
database: <%= database_name || app_name %>_test
hosts:
Expand Down
2 changes: 1 addition & 1 deletion spec/config/mongoid.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test:
sessions:
clients:
default:
database: mongoid_test
hosts:
Expand Down
8 changes: 4 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def database_id_alt
end

CONFIG = {
sessions: {
clients: {
default: {
database: database_id,
hosts: [ "#{HOST}:#{PORT}" ],
Expand All @@ -75,9 +75,9 @@ def database_id_alt
}

def purge_database_alt!
session = Mongoid::Sessions.default
session.use(database_id_alt)
session.collections.each do |collection|
client = Mongoid::Sessions.default
client.use(database_id_alt)
client.collections.each do |collection|
collection.drop
end
end
Expand Down

0 comments on commit 657650b

Please sign in to comment.