Skip to content

Commit f2bdc18

Browse files
MONGOID-5270: Follow-ups to tally PR (#5351)
* Follow-ups to tally PR: - Remove unused variable "k" in #extract value - Add missing code comment - Minor code comment fixes * Use pipe doc syntax * More pipes Co-authored-by: shields <[email protected]>
1 parent 478f0aa commit f2bdc18

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

lib/mongoid/contextual/memory.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def destroy
7474
# @example Get the distinct values.
7575
# context.distinct(:name)
7676
#
77-
# @param [ String, Symbol ] field The name of the field.
77+
# @param [ String | Symbol ] field The name of the field.
7878
#
7979
# @return [ Array<Object> ] The distinct values for the field.
8080
def distinct(field)
@@ -215,7 +215,7 @@ def length
215215
#
216216
# @param [ Integer ] value The number of documents to return.
217217
#
218-
# @return [ Mongo ] The context.
218+
# @return [ Memory ] The context.
219219
def limit(value)
220220
self.limiting = value
221221
self
@@ -233,6 +233,14 @@ def pluck(*fields)
233233
documents.pluck(*fields)
234234
end
235235

236+
# Tally the field values in memory.
237+
#
238+
# @example Get the counts of values in memory.
239+
# context.tally(:name)
240+
#
241+
# @param [ String | Symbol ] field Field to tally.
242+
#
243+
# @return [ Hash ] The hash of counts.
236244
def tally(field)
237245
return documents.each_with_object({}) do |d, acc|
238246
v = retrieve_value_at_path(d, field)
@@ -248,7 +256,7 @@ def tally(field)
248256
#
249257
# @param [ Integer ] value The number of documents to skip.
250258
#
251-
# @return [ Mongo ] The context.
259+
# @return [ Memory ] The context.
252260
def skip(value)
253261
self.skipping = value
254262
self
@@ -262,7 +270,7 @@ def skip(value)
262270
# @param [ Hash ] values The sorting values as field/direction(1/-1)
263271
# pairs.
264272
#
265-
# @return [ Mongo ] The context.
273+
# @return [ Memory ] The context.
266274
def sort(values)
267275
in_place_sort(values) and self
268276
end

lib/mongoid/contextual/mongo.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ def last(opts = {})
377377
end
378378
end
379379

380-
# Get's the number of documents matching the query selector.
380+
# Returns the number of documents in the database matching
381+
# the query selector.
381382
#
382383
# @example Get the length.
383384
# context.length
@@ -832,7 +833,6 @@ def fetch_and_demongoize(obj, meth, field)
832833
def extract_value(attrs, field_name)
833834
i = 1
834835
num_meths = field_name.count('.') + 1
835-
k = klass
836836
curr = attrs.dup
837837

838838
klass.traverse_association_tree(field_name) do |meth, obj, is_field|
@@ -870,10 +870,6 @@ def extract_value(attrs, field_name)
870870
fetch_and_demongoize(curr, meth, field)
871871
end
872872

873-
# If it's a relation, update the current klass with the relation klass.
874-
if !is_field && !obj.nil?
875-
k = obj.klass
876-
end
877873
i += 1
878874
end
879875
curr
@@ -910,7 +906,7 @@ def demongoize_with_field(field, value, is_translation)
910906
# again, we already have the translation. If it's an _translations
911907
# field, don't demongoize, we want the full hash not just a
912908
# specific translation.
913-
# If it is a hash, and it's not a transaltions field, we need to
909+
# If it is a hash, and it's not a translations field, we need to
914910
# demongoize to get the correct translation.
915911
if field.localized? && (!value.is_a?(Hash) || is_translation)
916912
value.class.demongoize(value)

lib/mongoid/contextual/none.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def ==(other)
5050
# @example Get the distinct values in null context.
5151
# context.distinct(:name)
5252
#
53-
# @param [ String, Symbol ] _field The name of the field.
53+
# @param [ String | Symbol ] _field The name of the field.
5454
#
5555
# @return [ Array ] An empty Array.
5656
def distinct(_field)
@@ -88,10 +88,10 @@ def exists?; false; end
8888
# @example Get the values for null context.
8989
# context.pluck(:name)
9090
#
91-
# @param [ String, Symbol, Array ] args Field or fields to pluck.
91+
# @param [ String | Symbol ] *_fields Field or fields to pluck.
9292
#
9393
# @return [ Array ] An empty Array.
94-
def pluck(*args)
94+
def pluck(*_fields)
9595
[]
9696
end
9797

@@ -100,10 +100,10 @@ def pluck(*args)
100100
# @example Get the values for null context.
101101
# context.tally(:name)
102102
#
103-
# @param [ String, Symbol ] arg Field to tally.
103+
# @param [ String | Symbol ] _field Field to tally.
104104
#
105105
# @return [ Hash ] An empty Hash.
106-
def tally(arg)
106+
def tally(_field)
107107
{}
108108
end
109109

0 commit comments

Comments
 (0)