Skip to content

Commit f833230

Browse files
Fix linter warnings (#5679)
1 parent a7edd84 commit f833230

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

lib/mongoid/association/macros.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# frozen_string_literal: true
2-
# rubocop:todo all
32

43
module Mongoid
54
module Association
6-
75
# This module contains the core macros for defining associations between
86
# documents. They can be either embedded or referenced.
97
module Macros
@@ -36,7 +34,7 @@ module Macros
3634
# @api private
3735
class_attribute :aliased_associations
3836

39-
# @return [ Set<String> ] The set of associations that are configured
37+
# @return [ Set<String> ] The set of associations that are configured
4038
# with :store_as parameter.
4139
class_attribute :stored_as_associations
4240

@@ -54,11 +52,11 @@ module Macros
5452
#
5553
# @return [ Hash ] The associations.
5654
def associations
57-
self.relations
55+
relations
5856
end
5957

58+
# Class methods for associations.
6059
module ClassMethods
61-
6260
# Adds the association back to the parent document. This macro is
6361
# necessary to set the references from the child back to the parent
6462
# document. If a child does not define this association calling
@@ -151,6 +149,8 @@ def belongs_to(name, options = {}, &block)
151149
define_association!(__method__, name, options, &block)
152150
end
153151

152+
# rubocop:disable Naming/PredicateName
153+
154154
# Adds a referenced association from a parent Document to many
155155
# Documents in another database or collection.
156156
#
@@ -217,15 +217,17 @@ def has_one(name, options = {}, &block)
217217
define_association!(__method__, name, options, &block)
218218
end
219219

220+
# rubocop:enable Naming/PredicateName
221+
220222
private
221223

222224
def define_association!(macro_name, name, options = {}, &block)
223225
Association::MACRO_MAPPING[macro_name].new(self, name, options, &block).tap do |assoc|
224226
assoc.setup!
225-
self.relations = self.relations.merge(name => assoc)
227+
self.relations = relations.merge(name => assoc)
226228
if assoc.embedded? && assoc.respond_to?(:store_as) && assoc.store_as != name
227-
self.aliased_associations[assoc.store_as] = name
228-
self.stored_as_associations << assoc.store_as
229+
aliased_associations[assoc.store_as] = name
230+
stored_as_associations << assoc.store_as
229231
end
230232
end
231233
end

lib/mongoid/attributes/processing.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
# frozen_string_literal: true
2-
# rubocop:todo all
32

43
module Mongoid
54
module Attributes
6-
75
# This module contains the behavior for processing attributes.
86
module Processing
9-
107
# Process the provided attributes casting them to their proper values if a
118
# field exists for them on the document. This will be limited to only the
129
# attributes provided in the supplied +Hash+ so that no extra nil values get
@@ -18,10 +15,11 @@ module Processing
1815
# @param [ Hash ] attrs The attributes to set.
1916
def process_attributes(attrs = nil)
2017
attrs ||= {}
21-
if !attrs.empty?
18+
unless attrs.empty?
2219
attrs = sanitize_for_mass_assignment(attrs)
2320
attrs.each_pair do |key, value|
2421
next if pending_attribute?(key, value)
22+
2523
process_attribute(key, value)
2624
end
2725
end
@@ -45,15 +43,15 @@ def process_attributes(attrs = nil)
4543
def pending_attribute?(key, value)
4644
name = key.to_s
4745
aliased = if aliased_associations.key?(name)
48-
aliased_associations[name]
49-
else
50-
name
51-
end
52-
if relations.has_key?(aliased)
46+
aliased_associations[name]
47+
else
48+
name
49+
end
50+
if relations.key?(aliased)
5351
set_pending_relation(name, aliased, value)
5452
return true
5553
end
56-
if nested_attributes.has_key?(aliased)
54+
if nested_attributes.key?(aliased)
5755
set_pending_nested(name, aliased, value)
5856
return true
5957
end
@@ -115,11 +113,12 @@ def pending_nested
115113
# @param [ Symbol ] name The name of the field.
116114
# @param [ Object ] value The value of the field.
117115
def process_attribute(name, value)
118-
if !respond_to?("#{name}=", true) && store_as = aliased_fields.invert[name.to_s]
116+
if !respond_to?("#{name}=", true) && (store_as = aliased_fields.invert[name.to_s])
119117
name = store_as
120118
end
121119
responds = respond_to?("#{name}=", true)
122120
raise Errors::UnknownAttribute.new(self.class, name) unless responds
121+
123122
send("#{name}=", value)
124123
end
125124

0 commit comments

Comments
 (0)