@@ -158,37 +158,47 @@ class Upconverter
158
158
#
159
159
# @since 2.1.0
160
160
OPTION_MAPPINGS = {
161
- :project => : projection,
162
- :skip => : skip,
163
- :limit => : limit,
164
- :batch_size => : batchSize
165
- }
161
+ :project => ' projection' ,
162
+ :skip => ' skip' ,
163
+ :limit => ' limit' ,
164
+ :batch_size => ' batchSize'
165
+ } . freeze
166
166
167
167
SPECIAL_FIELD_MAPPINGS = {
168
- :$readPreference => : readPreference,
169
- :$orderby => : sort,
170
- :$hint => : hint,
171
- :$comment => : comment,
172
- :$returnKey => : returnKey,
173
- :$snapshot => : snapshot,
174
- :$maxScan => : maxScan,
175
- :$max => : max,
176
- :$min => : min,
177
- :$maxTimeMS => : maxTimeMS,
178
- :$showDiskLoc => : showRecordId,
179
- :$explain => : explain
180
- }
168
+ :$readPreference => ' readPreference' ,
169
+ :$orderby => ' sort' ,
170
+ :$hint => ' hint' ,
171
+ :$comment => ' comment' ,
172
+ :$returnKey => ' returnKey' ,
173
+ :$snapshot => ' snapshot' ,
174
+ :$maxScan => ' maxScan' ,
175
+ :$max => ' max' ,
176
+ :$min => ' min' ,
177
+ :$maxTimeMS => ' maxTimeMS' ,
178
+ :$showDiskLoc => ' showRecordId' ,
179
+ :$explain => ' explain'
180
+ } . freeze
181
181
182
182
# Mapping of flags to find command options.
183
183
#
184
184
# @since 2.1.0
185
185
FLAG_MAPPINGS = {
186
- :tailable_cursor => :tailable ,
187
- :oplog_replay => :oplogReplay ,
188
- :no_cursor_timeout => :noCursorTimeout ,
189
- :await_data => :awaitData ,
190
- :partial => :allowPartialResults
191
- }
186
+ :tailable_cursor => 'tailable' ,
187
+ :oplog_replay => 'oplogReplay' ,
188
+ :no_cursor_timeout => 'noCursorTimeout' ,
189
+ :await_data => 'awaitData' ,
190
+ :partial => 'allowPartialResults'
191
+ } . freeze
192
+
193
+ # Find command constant.
194
+ #
195
+ # @since 2.1.0
196
+ FIND = 'find' . freeze
197
+
198
+ # Filter attribute constant.
199
+ #
200
+ # @since 2.1.0
201
+ FILTER = 'filter' . freeze
192
202
193
203
# @return [ String ] collection The name of the collection.
194
204
attr_reader :collection
@@ -242,7 +252,7 @@ def command
242
252
#
243
253
# @since 2.1.0
244
254
def command_name
245
- command? ? filter . keys . first : 'find'
255
+ command? ? filter . keys . first : FIND
246
256
end
247
257
248
258
private
@@ -257,16 +267,16 @@ def op_command
257
267
258
268
def find_command
259
269
document = BSON ::Document . new
260
- document [ :find ] = collection
261
- document [ :filter ] = filter [ :$query ] ? filter [ :$query ] : filter
270
+ document . store ( FIND , collection )
271
+ document . store ( FILTER , filter [ :$query ] ? filter [ :$query ] : filter )
262
272
OPTION_MAPPINGS . each do |legacy , option |
263
- document [ option ] = options [ legacy ] unless options [ legacy ] . nil?
273
+ document . store ( option , options [ legacy ] ) unless options [ legacy ] . nil?
264
274
end
265
275
SPECIAL_FIELD_MAPPINGS . each do |special , normal |
266
- document [ normal ] = filter [ special ] unless filter [ special ] . nil?
276
+ document . store ( normal , filter [ special ] ) unless filter [ special ] . nil?
267
277
end
268
278
FLAG_MAPPINGS . each do |legacy , flag |
269
- document [ flag ] = true if flags . include? ( legacy )
279
+ document . store ( flag , true ) if flags . include? ( legacy )
270
280
end
271
281
document
272
282
end
0 commit comments