Skip to content

Commit

Permalink
fix linter complaints for Mongo::Collection::View
Browse files Browse the repository at this point in the history
  • Loading branch information
jamis committed Nov 1, 2023
1 parent 2961065 commit c17bad6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ Layout/SpaceInsideArrayLiteralBrackets:
Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: false

Lint/Debugger:
DebuggerMethods:
- p

Metrics/ModuleLength:
Enabled: false

Expand Down
21 changes: 11 additions & 10 deletions lib/mongo/collection/view.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# frozen_string_literal: true
# rubocop:todo all

# Copyright (C) 2014-2020 MongoDB Inc.
#
Expand Down Expand Up @@ -27,7 +26,6 @@

module Mongo
class Collection

# Representation of a query and options producing a result set of documents.
#
# A +View+ can be modified using helpers. Helpers can be chained,
Expand Down Expand Up @@ -72,7 +70,7 @@ class View
# Delegate to the cluster for the next primary.
def_delegators :cluster, :next_primary

alias :selector :filter
alias selector filter

# Compare two +View+ objects.
#
Expand All @@ -85,11 +83,12 @@ class View
# @since 2.0.0
def ==(other)
return false unless other.is_a?(View)

collection == other.collection &&
filter == other.filter &&
options == other.options
filter == other.filter &&
options == other.options
end
alias_method :eql?, :==
alias eql? ==

# A hash value for the +View+ composed of the collection namespace,
# hash of the options and hash of the filter.
Expand All @@ -101,7 +100,7 @@ def ==(other)
#
# @since 2.0.0
def hash
[ collection.namespace, options.hash, filter.hash ].hash
[ collection.namespace, options, filter ].hash
end

# Creates a new +View+.
Expand Down Expand Up @@ -180,8 +179,8 @@ def initialize(collection, filter = {}, options = {})
#
# @since 2.0.0
def inspect
"#<Mongo::Collection::View:0x#{object_id} namespace='#{collection.namespace}'" +
" @filter=#{filter.to_s} @options=#{options.to_s}>"
"#<Mongo::Collection::View:0x#{object_id} namespace='#{collection.namespace}' " \
"@filter=#{filter} @options=#{options}>"
end

# Get the write concern on this +View+.
Expand All @@ -208,7 +207,9 @@ def new(options)
View.new(collection, filter, options)
end

def view; self; end
def view
self
end

def with_session(opts = {}, &block)
client.send(:with_session, @options.merge(opts), &block)
Expand Down
8 changes: 3 additions & 5 deletions spec/mongo/client_construction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2659,11 +2659,9 @@
new_client.cluster.next_primary

# Diagnostics
# rubocop:disable Style/IfUnlessModifier, Lint/Debugger
unless subscriber.started_events.empty?
p subscriber.started_events
end
# rubocop:enable Style/IfUnlessModifier, Lint/Debugger
# rubocop:disable Lint/Debugger
p subscriber.started_events unless subscriber.started_events.empty?
# rubocop:enable Lint/Debugger

expect(subscriber.started_events.length).to eq 0
expect(new_client.cluster.topology.class).not_to be Mongo::Cluster::Topology::Unknown
Expand Down

0 comments on commit c17bad6

Please sign in to comment.