Class: Mongo3::User
Overview
Administer users on a connection
Instance Method Summary
collapse
Methods inherited from Zone
#initialize
Constructor Details
This class inherits a constructor from Mongo3::Zone
Instance Method Details
#add(path, user_name, password) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/mongo3/user.rb', line 9
def add( path, user_name, password )
connect_for( path ) do |con|
user_cltn = users( con )
row = { :user => user_name }
user = user_cltn.find_one( row )
raise "User #{user_name} already exists!" if user
row[:pwd] = Mongo::Support.hash_password( user_name, password )
return user_cltn.save( row )
end
end
|
#clear!(path) ⇒ Object
22
23
24
25
26
|
# File 'lib/mongo3/user.rb', line 22
def clear!( path )
connect_for( path ) do |con|
res = users( con ).remove( {} )
end
end
|
#delete(path, id) ⇒ Object
32
33
34
35
36
|
# File 'lib/mongo3/user.rb', line 32
def delete( path, id )
connect_for( path ) do |con|
res = users( con ).remove( :_id => BSON::ObjectID.from_string( id ) )
end
end
|
#list(path, page, per_page = 10) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/mongo3/user.rb', line 38
def list( path, page, per_page=10 )
connect_for( path ) do |con|
user_cltn = users( con )
list = WillPaginate::Collection.create( page, per_page, user_cltn.size ) do ||
offset = (page-1)*per_page
results = user_cltn.find( {},
:sort => [['user', Mongo::ASCENDING]],
:skip => offset,
:limit => per_page ).to_a
return .replace( results )
end
end
end
|
#rename(zone, old_name, new_name) ⇒ Object
28
29
30
|
# File 'lib/mongo3/user.rb', line 28
def rename( zone, old_name, new_name )
raise "NYI"
end
|