Skip to content

Commit d72a037

Browse files
committed
Rubocop.
1 parent 6608cda commit d72a037

22 files changed

Lines changed: 301 additions & 148 deletions

.rubocop_todo.yml

Lines changed: 116 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,102 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2020-04-10 17:25:32 -0500 using RuboCop version 0.48.1.
3+
# on 2025-12-31 23:05:04 UTC using RuboCop version 1.82.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 7
10-
# Configuration parameters: Include.
11-
# Include: **/Gemfile, **/gems.rb
12-
Bundler/DuplicatedGem:
9+
# Offense count: 1
10+
Gemspec/RequiredRubyVersion:
1311
Exclude:
14-
- 'Gemfile'
12+
- 'mongoid-history.gemspec'
1513

16-
# Offense count: 3
17-
Lint/HandleExceptions:
14+
# Offense count: 1
15+
# This cop supports safe autocorrection (--autocorrect).
16+
# Configuration parameters: EnforcedStyleAlignWith.
17+
# SupportedStylesAlignWith: either, start_of_block, start_of_line
18+
Layout/BlockAlignment:
1819
Exclude:
19-
- 'spec/unit/trackable_spec.rb'
20+
- 'lib/mongoid/history/tracker.rb'
2021

21-
# Offense count: 3
22-
Lint/ParenthesesAsGroupedExpression:
22+
# Offense count: 170
23+
# Configuration parameters: AllowedMethods.
24+
# AllowedMethods: enums
25+
Lint/ConstantDefinitionInBlock:
26+
Enabled: false
27+
28+
# Offense count: 1
29+
# This cop supports unsafe autocorrection (--autocorrect-all).
30+
Lint/NonDeterministicRequireOrder:
2331
Exclude:
24-
- 'spec/integration/integration_spec.rb'
25-
- 'spec/integration/nested_embedded_polymorphic_documents_spec.rb'
32+
- 'spec/spec_helper.rb'
2633

27-
# Offense count: 22
34+
# Offense count: 21
35+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
2836
Metrics/AbcSize:
29-
Max: 52
37+
Max: 51
3038

31-
# Offense count: 122
32-
# Configuration parameters: CountComments, ExcludedMethods.
39+
# Offense count: 129
40+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
41+
# AllowedMethods: refine
3342
Metrics/BlockLength:
34-
Max: 900
43+
Max: 874
3544

3645
# Offense count: 1
37-
# Configuration parameters: CountComments.
46+
# Configuration parameters: CountComments, CountAsOne.
3847
Metrics/ClassLength:
39-
Max: 121
48+
Max: 127
4049

41-
# Offense count: 6
50+
# Offense count: 10
51+
# Configuration parameters: AllowedMethods, AllowedPatterns.
4252
Metrics/CyclomaticComplexity:
43-
Max: 13
44-
45-
# Offense count: 412
46-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
47-
# URISchemes: http, https
48-
Metrics/LineLength:
49-
Max: 688
53+
Max: 15
5054

51-
# Offense count: 17
52-
# Configuration parameters: CountComments.
55+
# Offense count: 18
56+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
5357
Metrics/MethodLength:
54-
Max: 23
58+
Max: 24
5559

5660
# Offense count: 2
57-
# Configuration parameters: CountComments.
61+
# Configuration parameters: CountComments, CountAsOne.
5862
Metrics/ModuleLength:
59-
Max: 200
63+
Max: 199
6064

61-
# Offense count: 6
65+
# Offense count: 9
66+
# Configuration parameters: AllowedMethods, AllowedPatterns.
6267
Metrics/PerceivedComplexity:
63-
Max: 15
68+
Max: 16
69+
70+
# Offense count: 1
71+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
72+
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
73+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
74+
Naming/FileName:
75+
Exclude:
76+
- 'Rakefile.rb'
77+
- 'lib/mongoid-history.rb'
78+
79+
# Offense count: 3
80+
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
81+
# SupportedStyles: snake_case, normalcase, non_integer
82+
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
83+
Naming/VariableNumber:
84+
Exclude:
85+
- 'spec/unit/my_instance_methods_spec.rb'
86+
- 'spec/unit/tracker_spec.rb'
87+
88+
# Offense count: 6
89+
# This cop supports unsafe autocorrection (--autocorrect-all).
90+
# Configuration parameters: AllowedMethods, AllowedPatterns.
91+
# AllowedMethods: ==, equal?, eql?
92+
Style/ClassEqualityComparison:
93+
Exclude:
94+
- 'lib/mongoid/history/attributes/base.rb'
95+
- 'lib/mongoid/history/options.rb'
96+
- 'perf/benchmark_modified_attributes_for_create.rb'
6497

6598
# Offense count: 15
99+
# Configuration parameters: AllowedConstants.
66100
Style/Documentation:
67101
Exclude:
68102
- 'spec/**/*'
@@ -78,22 +112,58 @@ Style/Documentation:
78112
- 'perf/benchmark_modified_attributes_for_create.rb'
79113
- 'perf/gc_suite.rb'
80114

81-
# Offense count: 3
82-
# Cop supports --auto-correct.
83-
Style/EachWithObject:
115+
# Offense count: 44
116+
# This cop supports unsafe autocorrection (--autocorrect-all).
117+
# Configuration parameters: EnforcedStyle.
118+
# SupportedStyles: always, always_true, never
119+
Style/FrozenStringLiteralComment:
120+
Enabled: false
121+
122+
# Offense count: 1
123+
# This cop supports unsafe autocorrection (--autocorrect-all).
124+
# Configuration parameters: AllowedReceivers.
125+
# AllowedReceivers: Thread.current
126+
Style/HashEachMethods:
84127
Exclude:
85-
- 'lib/mongoid/history/trackable.rb'
86128
- 'lib/mongoid/history/tracker.rb'
87129

88-
# Offense count: 2
89-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
90-
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
91-
Style/FileName:
130+
# Offense count: 1
131+
# This cop supports unsafe autocorrection (--autocorrect-all).
132+
Style/HashTransformValues:
92133
Exclude:
93-
- 'Dangerfile'
94-
- 'lib/mongoid-history.rb'
134+
- 'perf/benchmark_modified_attributes_for_create.rb'
95135

96-
# Offense count: 1
136+
# Offense count: 4
137+
# This cop supports safe autocorrection (--autocorrect).
138+
Style/IfUnlessModifier:
139+
Exclude:
140+
- 'lib/mongoid/history/trackable.rb'
141+
142+
# Offense count: 2
97143
Style/MultilineBlockChain:
98144
Exclude:
99145
- 'lib/mongoid/history/tracker.rb'
146+
- 'perf/benchmark_modified_attributes_for_create.rb'
147+
148+
# Offense count: 2
149+
# This cop supports unsafe autocorrection (--autocorrect-all).
150+
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
151+
# AllowedMethods: present?, blank?, presence, try, try!
152+
Style/SafeNavigation:
153+
Exclude:
154+
- 'lib/mongoid/history/trackable.rb'
155+
156+
# Offense count: 2
157+
# This cop supports unsafe autocorrection (--autocorrect-all).
158+
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
159+
# AllowedMethods: define_method
160+
Style/SymbolProc:
161+
Exclude:
162+
- 'spec/unit/callback_options_spec.rb'
163+
164+
# Offense count: 9
165+
# This cop supports safe autocorrection (--autocorrect).
166+
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
167+
# URISchemes: http, https
168+
Layout/LineLength:
169+
Max: 688

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ require 'bundler'
22
begin
33
Bundler.setup(:default, :development)
44
rescue Bundler::BundlerError => e
5-
$stderr.puts e.message
6-
$stderr.puts 'Run `bundle install` to install missing gems'
5+
warn e.message
6+
warn 'Run `bundle install` to install missing gems'
77
exit e.status_code
88
end
99

lib/mongoid/history.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ module History
1414
GLOBAL_TRACK_HISTORY_FLAG = 'mongoid_history_trackable_enabled'.freeze
1515

1616
class << self
17-
attr_accessor :tracker_class_name
18-
attr_accessor :trackable_settings
19-
attr_accessor :modifier_class_name
20-
attr_accessor :current_user_method
17+
attr_accessor :tracker_class_name, :trackable_settings, :modifier_class_name, :current_user_method
2118

2219
def disable
2320
original_flag = store[GLOBAL_TRACK_HISTORY_FLAG]

lib/mongoid/history/attributes/create.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def attributes
66
@attributes = {}
77
changes.each do |k, v|
88
next unless trackable_class.tracked_field?(k, :create)
9+
910
@attributes[k] = format_field(k, v)
1011
end
1112
insert_embeds_one_changes
@@ -23,6 +24,7 @@ def insert_embeds_one_changes
2324
rel = aliased_fields.key(rel) || rel
2425
obj = trackable.send(rel)
2526
next if !obj || (obj.respond_to?(paranoia_field) && obj.public_send(paranoia_field).present?)
27+
2628
@attributes[rel] = [nil, format_embeds_one_relation(rel, obj.attributes)]
2729
end
2830
end

lib/mongoid/history/attributes/destroy.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module Attributes
44
class Destroy < ::Mongoid::History::Attributes::Base
55
def attributes
66
@attributes = {}
7-
trackable.attributes.each { |k, v| @attributes[k] = [format_field(k, v), nil] if trackable_class.tracked_field?(k, :destroy) }
7+
trackable.attributes.each do |k, v|
8+
@attributes[k] = [format_field(k, v), nil] if trackable_class.tracked_field?(k, :destroy)
9+
end
810
insert_embeds_one_changes
911
insert_embeds_many_changes
1012
@attributes
@@ -16,16 +18,18 @@ def insert_embeds_one_changes
1618
trackable_class.tracked_embeds_one
1719
.map { |rel| aliased_fields.key(rel) || rel }
1820
.each do |rel|
19-
obj = trackable.send(rel)
20-
@attributes[rel] = [format_embeds_one_relation(rel, obj.attributes), nil] if obj
21+
obj = trackable.send(rel)
22+
@attributes[rel] = [format_embeds_one_relation(rel, obj.attributes), nil] if obj
2123
end
2224
end
2325

2426
def insert_embeds_many_changes
2527
trackable_class.tracked_embeds_many
2628
.map { |rel| aliased_fields.key(rel) || rel }
2729
.each do |rel|
28-
@attributes[rel] = [trackable.send(rel).map { |obj| format_embeds_many_relation(rel, obj.attributes) }, nil]
30+
@attributes[rel] = [trackable.send(rel).map do |obj|
31+
format_embeds_many_relation(rel, obj.attributes)
32+
end, nil]
2933
end
3034
end
3135
end

lib/mongoid/history/attributes/update.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ def changes_from_parent
2121
track_blank_changes = trackable_class.history_trackable_options[:track_blank_changes]
2222
parent_changes = {}
2323
changes.each do |k, v|
24-
change_value = begin
25-
if trackable_class.tracked_embeds_one?(k)
26-
embeds_one_changes_from_parent(k, v)
27-
elsif trackable_class.tracked_embeds_many?(k)
28-
embeds_many_changes_from_parent(k, v)
29-
elsif trackable_class.tracked?(k, :update)
30-
{ k => format_field(k, v) } unless !track_blank_changes && v.all?(&:blank?)
31-
end
32-
end
24+
change_value = if trackable_class.tracked_embeds_one?(k)
25+
embeds_one_changes_from_parent(k, v)
26+
elsif trackable_class.tracked_embeds_many?(k)
27+
embeds_many_changes_from_parent(k, v)
28+
elsif trackable_class.tracked?(k, :update)
29+
{ k => format_field(k, v) } unless !track_blank_changes && v.all?(&:blank?)
30+
end
31+
3332
parent_changes.merge!(change_value) if change_value.present?
3433
end
3534
parent_changes

lib/mongoid/history/options.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def scope
1414

1515
def prepared
1616
return @prepared if @prepared
17+
1718
@prepared = options.dup
1819
prepare_skipped_fields
1920
prepare_formatted_fields
@@ -58,10 +59,14 @@ def prepare_formatted_fields
5859

5960
if format.class == Hash && trackable.embeds_many?(field)
6061
relation_class = trackable.relation_class_of(field)
61-
formats[field] = format.inject({}) { |a, e| a.merge(relation_class.database_field_name(e.first) => e.last) }
62+
formats[field] = format.inject({}) do |a, e|
63+
a.merge(relation_class.database_field_name(e.first) => e.last)
64+
end
6265
elsif format.class == Hash && trackable.embeds_one?(field)
6366
relation_class = trackable.relation_class_of(field)
64-
formats[field] = format.inject({}) { |a, e| a.merge(relation_class.database_field_name(e.first) => e.last) }
67+
formats[field] = format.inject({}) do |a, e|
68+
a.merge(relation_class.database_field_name(e.first) => e.last)
69+
end
6570
else
6671
formats[field] = format
6772
end
@@ -166,7 +171,9 @@ def track_relation(field, kind, field_options)
166171
@prepared[:relations][kind][field] = if field_options.blank?
167172
relation_class.fields.keys
168173
else
169-
%w[_id] | field_options.map { |opt| relation_class.database_field_name(opt) }
174+
%w[_id] | field_options.map do |opt|
175+
relation_class.database_field_name(opt)
176+
end
170177
end
171178
end
172179

0 commit comments

Comments
 (0)