lib/mongo/auth/user/view.rb in mongo-2.4.3 vs lib/mongo/auth/user/view.rb in mongo-2.5.0.beta
- old
+ new
@@ -23,30 +23,35 @@
extend Forwardable
# @return [ Database ] database The view's database.
attr_reader :database
- def_delegators :database, :cluster, :read_preference
+ def_delegators :database, :cluster, :read_preference, :client
def_delegators :cluster, :next_primary
# Create a new user in the database.
#
# @example Create a new read/write user.
# view.create('user', password: 'password', roles: [ 'readWrite' ])
#
# @param [ Auth::User, String ] user_or_name The user object or user name.
# @param [ Hash ] options The user options.
#
+ # @option options [ Session ] :session The session to use for the operation.
+ #
# @return [ Result ] The command response.
#
# @since 2.0.0
def create(user_or_name, options = {})
user = generate(user_or_name, options)
- Operation::Write::CreateUser.new(
- user: user,
- db_name: database.name
- ).execute(next_primary)
+ client.send(:with_session, options) do |session|
+ Operation::Write::CreateUser.new(
+ user: user,
+ db_name: database.name,
+ session: session
+ ).execute(next_primary)
+ end
end
# Initialize the new user view.
#
# @example Initialize the user view.
@@ -63,60 +68,77 @@
#
# @example Remove the user from the database.
# view.remove('user')
#
# @param [ String ] name The user name.
+ # @param [ Hash ] options The options for the remove operation.
#
+ # @option options [ Session ] :session The session to use for the operation.
+ #
# @return [ Result ] The command response.
#
# @since 2.0.0
- def remove(name)
- Operation::Write::RemoveUser.new(
- user_name: name,
- db_name: database.name
- ).execute(next_primary)
+ def remove(name, options = {})
+ client.send(:with_session, options) do |session|
+ Operation::Write::RemoveUser.new(
+ user_name: name,
+ db_name: database.name,
+ session: session
+ ).execute(next_primary)
+ end
end
# Update a user in the database.
#
# @example Update a user.
# view.update('name', password: 'testpwd')
#
# @param [ Auth::User, String ] user_or_name The user object or user name.
# @param [ Hash ] options The user options.
#
+ # @option options [ Session ] :session The session to use for the operation.
+ #
# @return [ Result ] The response.
#
# @since 2.0.0
def update(user_or_name, options = {})
- user = generate(user_or_name, options)
- Operation::Write::UpdateUser.new(
- user: user,
- db_name: database.name
- ).execute(next_primary)
+ client.send(:with_session, options) do |session|
+ user = generate(user_or_name, options)
+ Operation::Write::UpdateUser.new(
+ user: user,
+ db_name: database.name,
+ session: session
+ ).execute(next_primary)
+ end
end
# Get info for a particular user in the database.
#
# @example Get a particular user's info.
# view.info('emily')
#
# @param [ String ] name The user name.
+ # @param [ Hash ] options The options for the info operation.
#
+ # @option options [ Session ] :session The session to use for the operation.
+ #
# @return [ Hash ] A document containing information on a particular user.
#
# @since 2.1.0
- def info(name)
- user_query(name).documents
+ def info(name, options = {})
+ user_query(name, options).documents
end
private
- def user_query(name)
- Operation::Commands::UserQuery.new(
- user_name: name,
- db_name: database.name
- ).execute(next_primary)
+ def user_query(name, options = {})
+ client.send(:with_session, options) do |session|
+ Operation::Commands::UserQuery.new(
+ user_name: name,
+ db_name: database.name,
+ session: session
+ ).execute(next_primary)
+ end
end
def generate(user, options)
user.is_a?(String) ? Auth::User.new({ user: user }.merge(options)) : user
end