Class: Mongo::Auth::User::View

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
build/ruby-driver-master/lib/mongo/auth/user/view.rb

Overview

Defines behavior for user related operation on databases.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database) ⇒ View

Initialize the new user view.

Examples:

Initialize the user view.

View::User.new(database)

Parameters:

Since:

  • 2.0.0



68
69
70
# File 'build/ruby-driver-master/lib/mongo/auth/user/view.rb', line 68

def initialize(database)
  @database = database
end

Instance Attribute Details

#databaseDatabase (readonly)

Returns database The view's database.

Returns:

  • (Database)

    database The view's database.

Since:

  • 2.0.0



29
30
31
# File 'build/ruby-driver-master/lib/mongo/auth/user/view.rb', line 29

def database
  @database
end

Instance Method Details

#create(user_or_name, options = {}) ⇒ Result

Create a new user in the database.

Examples:

Create a new read/write user.

view.create('user', password: 'password', roles: [ 'readWrite' ])

Parameters:

  • user_or_name (Auth::User, String)

    The user object or user name.

  • options (Hash) (defaults to: {})

    The user options.

Options Hash (options):

  • :session (Session)

    The session to use for the operation.

  • :write_concern (Hash)

    The write concern options.

Returns:

  • (Result)

    The command response.

Since:

  • 2.0.0



48
49
50
51
52
53
54
55
56
57
58
# File 'build/ruby-driver-master/lib/mongo/auth/user/view.rb', line 48

def create(user_or_name, options = {})
  user = generate(user_or_name, options)
  execute_operation(options) do |session|
    Operation::CreateUser.new(
      user: user,
      db_name: database.name,
      session: session,
      write_concern: options[:write_concern] && WriteConcern.get(options[:write_concern]),
    )
  end
end

#info(name, options = {}) ⇒ Array

Get info for a particular user in the database.

Examples:

Get a particular user's info.

view.info('emily')

Parameters:

  • name (String)

    The user name.

  • options (Hash) (defaults to: {})

    The options for the info operation.

Options Hash (options):

  • :session (Session)

    The session to use for the operation.

Returns:

  • (Array)

    An array wrapping a document containing information on a particular user.

Since:

  • 2.1.0



136
137
138
# File 'build/ruby-driver-master/lib/mongo/auth/user/view.rb', line 136

def info(name, options = {})
  user_query(name, options).documents
end

#remove(name, options = {}) ⇒ Result

Remove a user from the database.

Examples:

Remove the user from the database.

view.remove('user')

Parameters:

  • name (String)

    The user name.

  • options (Hash) (defaults to: {})

    The options for the remove operation.

Options Hash (options):

  • :session (Session)

    The session to use for the operation.

  • :write_concern (Hash)

    The write concern options.

Returns:

  • (Result)

    The command response.

Since:

  • 2.0.0



86
87
88
89
90
91
92
93
94
95
# File 'build/ruby-driver-master/lib/mongo/auth/user/view.rb', line 86

def remove(name, options = {})
  execute_operation(options) do |session|
    Operation::RemoveUser.new(
      user_name: name,
      db_name: database.name,
      session: session,
      write_concern: options[:write_concern] && WriteConcern.get(options[:write_concern]),
    )
  end
end

#update(user_or_name, options = {}) ⇒ Result

Update a user in the database.

Examples:

Update a user.

view.update('name', password: 'testpwd')

Parameters:

  • user_or_name (Auth::User, String)

    The user object or user name.

  • options (Hash) (defaults to: {})

    The user options.

Options Hash (options):

  • :session (Session)

    The session to use for the operation.

  • :write_concern (Hash)

    The write concern options.

Returns:

  • (Result)

    The response.

Since:

  • 2.0.0



111
112
113
114
115
116
117
118
119
120
121
# File 'build/ruby-driver-master/lib/mongo/auth/user/view.rb', line 111

def update(user_or_name, options = {})
  user = generate(user_or_name, options)
  execute_operation(options) do |session|
    Operation::UpdateUser.new(
      user: user,
      db_name: database.name,
      session: session,
      write_concern: options[:write_concern] && WriteConcern.get(options[:write_concern]),
    )
  end
end