lib/moped/session.rb in moped-1.0.0.rc vs lib/moped/session.rb in moped-1.0.0
- old
+ new
@@ -26,51 +26,92 @@
#
# session = Moped::Session.new %w[127.0.0.1:27017],
# session.with(database: "admin").login("admin", "s3cr3t")
#
class Session
- extend Forwardable
# @attribute [r] cluster The session cluster.
# @attribute [r] context The session context.
# @attribute [r] options The session options.
attr_reader :cluster, :context, :options
- # @method [](collection)
# Return +collection+ from the current database.
#
# @param (see Moped::Database#[])
+ #
# @return (see Moped::Database#[])
- delegate :"[]" => :current_database
+ #
+ # @since 1.0.0
+ def [](name)
+ current_database[name]
+ end
- # @method command(command)
+ # Return non system collection name from the current database.
+ #
+ # @param (see Moped::Database#collection_names)
+ #
+ # @return (see Moped::Database#collection_names)
+ #
+ # @since 1.0.0
+ def collection_names
+ current_database.collection_names
+ end
+
+ # Return non system collection name from the current database.
+ #
+ # @param (see Moped::Database#collections)
+ #
+ # @return (see Moped::Database#collections)
+ #
+ # @since 1.0.0
+ def collections
+ current_database.collections
+ end
+
# Run +command+ on the current database.
#
# @param (see Moped::Database#command)
+ #
# @return (see Moped::Database#command)
- delegate :command => :current_database
+ #
+ # @since 1.0.0
+ def command(op)
+ current_database.command(op)
+ end
- # @method drop
# Drop the current database.
#
# @param (see Moped::Database#drop)
+ #
# @return (see Moped::Database#drop)
- delegate :drop => :current_database
+ #
+ # @since 1.0.0
+ def drop
+ current_database.drop
+ end
- # @method login(username, password)
# Log in with +username+ and +password+ on the current database.
#
# @param (see Moped::Database#login)
+ #
# @raise (see Moped::Database#login)
- delegate :login => :current_database
+ #
+ # @since 1.0.0
+ def login(username, password)
+ current_database.login(username, password)
+ end
- # @method logout
# Log out from the current database.
#
# @param (see Moped::Database#logout)
+ #
# @raise (see Moped::Database#login)
- delegate :logout => :current_database
+ #
+ # @since 1.0.0
+ def logout
+ current_database.logout
+ end
# Get the session's consistency.
#
# @example Get the session consistency.
# session.consistency
@@ -166,15 +207,10 @@
#
# @return [ Boolean, Hash ] The safety level for this session.
#
# @since 1.0.0
def safety
- safe = options[:safe]
- case safe
- when false then false
- when true then { safe: true }
- else safe
- end
+ options[:safe].__safe_options__
end
# Switch the session's current database.
#
# @example Switch the current database.