@@ -25,7 +25,7 @@ class View
2525 # @return [ Database ] database The view's database.
2626 attr_reader :database
2727
28- def_delegators :database , :cluster , :read_preference
28+ def_delegators :database , :cluster , :read_preference , :client
2929 def_delegators :cluster , :next_primary
3030
3131 # Create a new user in the database.
@@ -36,15 +36,20 @@ class View
3636 # @param [ Auth::User, String ] user_or_name The user object or user name.
3737 # @param [ Hash ] options The user options.
3838 #
39+ # @option options [ Session ] :session The session to use for the operation.
40+ #
3941 # @return [ Result ] The command response.
4042 #
4143 # @since 2.0.0
4244 def create ( user_or_name , options = { } )
4345 user = generate ( user_or_name , options )
44- Operation ::Write ::CreateUser . new (
45- user : user ,
46- db_name : database . name
47- ) . execute ( next_primary )
46+ client . send ( :with_session , options ) do |session |
47+ Operation ::Write ::CreateUser . new (
48+ user : user ,
49+ db_name : database . name ,
50+ session : session
51+ ) . execute ( next_primary )
52+ end
4853 end
4954
5055 # Initialize the new user view.
@@ -65,15 +70,21 @@ def initialize(database)
6570 # view.remove('user')
6671 #
6772 # @param [ String ] name The user name.
73+ # @param [ Hash ] options The options for the remove operation.
74+ #
75+ # @option options [ Session ] :session The session to use for the operation.
6876 #
6977 # @return [ Result ] The command response.
7078 #
7179 # @since 2.0.0
72- def remove ( name )
73- Operation ::Write ::RemoveUser . new (
74- user_name : name ,
75- db_name : database . name
76- ) . execute ( next_primary )
80+ def remove ( name , options = { } )
81+ client . send ( :with_session , options ) do |session |
82+ Operation ::Write ::RemoveUser . new (
83+ user_name : name ,
84+ db_name : database . name ,
85+ session : session
86+ ) . execute ( next_primary )
87+ end
7788 end
7889
7990 # Update a user in the database.
@@ -84,15 +95,20 @@ def remove(name)
8495 # @param [ Auth::User, String ] user_or_name The user object or user name.
8596 # @param [ Hash ] options The user options.
8697 #
98+ # @option options [ Session ] :session The session to use for the operation.
99+ #
87100 # @return [ Result ] The response.
88101 #
89102 # @since 2.0.0
90103 def update ( user_or_name , options = { } )
91- user = generate ( user_or_name , options )
92- Operation ::Write ::UpdateUser . new (
93- user : user ,
94- db_name : database . name
95- ) . execute ( next_primary )
104+ client . send ( :with_session , options ) do |session |
105+ user = generate ( user_or_name , options )
106+ Operation ::Write ::UpdateUser . new (
107+ user : user ,
108+ db_name : database . name ,
109+ session : session
110+ ) . execute ( next_primary )
111+ end
96112 end
97113
98114 # Get info for a particular user in the database.
@@ -101,21 +117,27 @@ def update(user_or_name, options = {})
101117 # view.info('emily')
102118 #
103119 # @param [ String ] name The user name.
120+ # @param [ Hash ] options The options for the info operation.
121+ #
122+ # @option options [ Session ] :session The session to use for the operation.
104123 #
105124 # @return [ Hash ] A document containing information on a particular user.
106125 #
107126 # @since 2.1.0
108- def info ( name )
109- user_query ( name ) . documents
127+ def info ( name , options = { } )
128+ user_query ( name , options ) . documents
110129 end
111130
112131 private
113132
114- def user_query ( name )
115- Operation ::Commands ::UserQuery . new (
116- user_name : name ,
117- db_name : database . name
118- ) . execute ( next_primary )
133+ def user_query ( name , options = { } )
134+ client . send ( :with_session , options ) do |session |
135+ Operation ::Commands ::UserQuery . new (
136+ user_name : name ,
137+ db_name : database . name ,
138+ session : session
139+ ) . execute ( next_primary )
140+ end
119141 end
120142
121143 def generate ( user , options )
0 commit comments