diff --git a/.rubocop.yml b/.rubocop.yml index d38f97fdb..0f74d985d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -241,6 +241,12 @@ Style/NumericLiterals: Style/NumericPredicate: Enabled: false +Style/OptionalBooleanParameter: + AllowedMethods: + - respond_to? + - respond_to_missing? + - set_parent= + Style/RaiseArgs: EnforcedStyle: compact diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8b95d8ee4..5a1f2ff5e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -830,25 +830,6 @@ Style/OpenStructUse: - 'spec/rails/controller_extension/controller_runtime_spec.rb' - 'spec/support/rails_mock.rb' -# Offense count: 17 -# Configuration parameters: AllowedMethods. -# AllowedMethods: respond_to_missing? -Style/OptionalBooleanParameter: - Exclude: - - 'lib/mongoid/association/embedded/cyclic.rb' - - 'lib/mongoid/association/many.rb' - - 'lib/mongoid/association/one.rb' - - 'lib/mongoid/association/referenced/has_many/enumerable.rb' - - 'lib/mongoid/atomic.rb' - - 'lib/mongoid/attributes/dynamic.rb' - - 'lib/mongoid/criteria.rb' - - 'lib/mongoid/criteria/queryable/extensions/string.rb' - - 'lib/mongoid/criteria/queryable/extensions/symbol.rb' - - 'lib/mongoid/criteria/queryable/key.rb' - - 'lib/mongoid/criteria/queryable/options.rb' - - 'spec/support/models/address.rb' - - 'spec/support/models/name.rb' - # Offense count: 38 # This cop supports safe autocorrection (--autocorrect). Style/RedundantCurrentDirectoryInPath: diff --git a/lib/mongoid/association/embedded/cyclic.rb b/lib/mongoid/association/embedded/cyclic.rb index ba1e7e085..3a7307c50 100644 --- a/lib/mongoid/association/embedded/cyclic.rb +++ b/lib/mongoid/association/embedded/cyclic.rb @@ -65,7 +65,7 @@ def recursively_embeds_many(options = {}) # or its children. def recursively_embeds_one(options = {}) embeds_one( - cyclic_child_name(false), + cyclic_child_name(many: false), options.merge(class_name: name, cyclic: true) ) embedded_in cyclic_parent_name, class_name: name, cyclic: true @@ -92,7 +92,7 @@ def cyclic_parent_name # # @return [ String ] "child_" plus the class name underscored in # singular or plural form. - def cyclic_child_name(many = true) + def cyclic_child_name(many: true) :"child_#{name.demodulize.underscore.send(many ? :pluralize : :singularize)}" end end diff --git a/lib/mongoid/atomic.rb b/lib/mongoid/atomic.rb index c0cdcfefd..04a79c6d6 100644 --- a/lib/mongoid/atomic.rb +++ b/lib/mongoid/atomic.rb @@ -116,7 +116,7 @@ def atomic_array_add_to_sets # person.atomic_updates(children) # # @return [ Hash ] The updates and their modifiers. - def atomic_updates(_use_indexes = false) + def atomic_updates(_use_indexes: false) process_flagged_destroys mods = Modifiers.new generate_atomic_updates(mods, self) diff --git a/lib/mongoid/criteria/queryable/expandable.rb b/lib/mongoid/criteria/queryable/expandable.rb index 4427e2e40..85c35eb70 100644 --- a/lib/mongoid/criteria/queryable/expandable.rb +++ b/lib/mongoid/criteria/queryable/expandable.rb @@ -37,7 +37,7 @@ module Expandable # # @return [ Array ] The expanded field and value. def expand_one_condition(field, value) - kv = field.__expr_part__(value.__expand_complex__, negating?) + kv = field.__expr_part__(value.__expand_complex__, negating: negating?) [kv.keys.first.to_s, kv.values.first] end diff --git a/lib/mongoid/criteria/queryable/extensions/string.rb b/lib/mongoid/criteria/queryable/extensions/string.rb index 9c90e372f..5656e8640 100644 --- a/lib/mongoid/criteria/queryable/extensions/string.rb +++ b/lib/mongoid/criteria/queryable/extensions/string.rb @@ -63,8 +63,8 @@ def __sort_option__ # @param [ true | false ] negating If the selection should be negated. # # @return [ Hash ] The selection. - def __expr_part__(value, negating = false) - ::String.__expr_part__(self, value, negating) + def __expr_part__(value, negating: false) + ::String.__expr_part__(self, value, negating: negating) end module ClassMethods @@ -79,7 +79,7 @@ module ClassMethods # @param [ true | false ] negating If the selection should be negated. # # @return [ Hash ] The selection. - def __expr_part__(key, value, negating = false) + def __expr_part__(key, value, negating: false) if negating { key => { "$#{__regexp?(value) ? 'not' : 'ne'}" => value } } else diff --git a/lib/mongoid/criteria/queryable/extensions/symbol.rb b/lib/mongoid/criteria/queryable/extensions/symbol.rb index dd195e3ba..b4640cfc7 100644 --- a/lib/mongoid/criteria/queryable/extensions/symbol.rb +++ b/lib/mongoid/criteria/queryable/extensions/symbol.rb @@ -17,8 +17,8 @@ module Symbol # @param [ true | false ] negating If the selection should be negated. # # @return [ Hash ] The selection. - def __expr_part__(value, negating = false) - ::String.__expr_part__(self, value, negating) + def __expr_part__(value, negating: false) + ::String.__expr_part__(self, value, negating: negating) end module ClassMethods diff --git a/lib/mongoid/criteria/queryable/key.rb b/lib/mongoid/criteria/queryable/key.rb index c5fbb41cb..1d95eb61c 100644 --- a/lib/mongoid/criteria/queryable/key.rb +++ b/lib/mongoid/criteria/queryable/key.rb @@ -131,8 +131,8 @@ def initialize(name, strategy, operator, expanded = nil, &block) # @param [ true | false ] negating If the selection should be negated. # # @return [ Hash ] The raw MongoDB selector. - def __expr_part__(object, negating = false) - { name.to_s => transform_value(object, negating) } + def __expr_part__(object, negating: false) + { name.to_s => transform_value(object, negating: negating) } end # Gets the raw selector condition that would be passed to Mongo. @@ -144,7 +144,7 @@ def __expr_part__(object, negating = false) # @param [ true | false ] negating If the selection should be negated. # # @return [ Hash ] The raw MongoDB selector. - def transform_value(value, negating = false) + def transform_value(value, negating: false) expr = block ? block[value] : value expr = { expanded => expr } if expanded expr = { operator => expr } diff --git a/lib/mongoid/criteria/queryable/mergeable.rb b/lib/mongoid/criteria/queryable/mergeable.rb index 5d4413a79..eb6fdfee7 100644 --- a/lib/mongoid/criteria/queryable/mergeable.rb +++ b/lib/mongoid/criteria/queryable/mergeable.rb @@ -261,7 +261,7 @@ def _mongoid_expand_keys(expr) result = BSON::Document.new expr.each do |field, value| - field.__expr_part__(value.__expand_complex__, negating?).each do |k, v| + field.__expr_part__(value.__expand_complex__, negating: negating?).each do |k, v| if (existing = result[k]) if existing.is_a?(Hash) # Existing value is an operator. diff --git a/lib/mongoid/criteria/queryable/optional.rb b/lib/mongoid/criteria/queryable/optional.rb index d32c123a5..96aba4591 100644 --- a/lib/mongoid/criteria/queryable/optional.rb +++ b/lib/mongoid/criteria/queryable/optional.rb @@ -119,7 +119,7 @@ def only(*args) options.store( :fields, args.inject(options[:fields] || {}) { |sub, field| sub.tap { sub[field] = 1 } }, - false + localize: false ) end end @@ -241,7 +241,7 @@ def without(*args) options.store( :fields, args.inject(options[:fields] || {}) { |sub, field| sub.tap { sub[field] = 0 } }, - false + localize: false ) end end diff --git a/lib/mongoid/criteria/queryable/options.rb b/lib/mongoid/criteria/queryable/options.rb index bd09d5d73..3fa0914bb 100644 --- a/lib/mongoid/criteria/queryable/options.rb +++ b/lib/mongoid/criteria/queryable/options.rb @@ -58,8 +58,8 @@ def sort # @param [ Object ] value The value to add. # # @return [ Object ] The stored object. - def store(key, value, localize = true) - super(key, evolve(value, localize)) + def store(key, value, localize: true) + super(key, evolve(value, localize: localize)) end alias_method :[]=, :store @@ -103,10 +103,10 @@ def __deep_copy__ # @param [ Object ] value The value to serialize. # # @return [ Object ] The serialized object. - def evolve(value, localize = true) + def evolve(value, localize: true) case value when Hash - evolve_hash(value, localize) + evolve_hash(value, localize: localize) else value end @@ -122,7 +122,7 @@ def evolve(value, localize = true) # @param [ Hash ] value The hash to serialize. # # @return [ Object ] The serialized hash. - def evolve_hash(value, localize = true) + def evolve_hash(value, localize: true) value.each_with_object({}) do |(field, val), hash| name, serializer = storage_pair(field) name = localized_key(name, serializer) if localize diff --git a/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb b/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb index 1a508c1f9..0dc55e854 100644 --- a/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +++ b/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb @@ -87,7 +87,7 @@ context 'with a regexp' do let(:specified) do - :field.__expr_part__(/test/, true) + :field.__expr_part__(/test/, negating: true) end it 'returns the symbol with the value negated' do @@ -99,7 +99,7 @@ context 'with anything else' do let(:specified) do - :field.__expr_part__('test', true) + :field.__expr_part__('test', negating: true) end it 'returns the symbol with the value negated' do