Skip to content

Commit b813b5d

Browse files
(PUP-11767) Enable Style/EachWithObject
1 parent d889f5d commit b813b5d

32 files changed

+45
-68
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,6 @@ Style/DoubleCopDisableDirective:
244244

245245
Style/EachForSimpleLoop:
246246
Enabled: true
247+
248+
Style/EachWithObject:
249+
Enabled: true

lib/puppet/confine/exists.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def message(value)
1616
end
1717

1818
def summary
19-
result.zip(values).inject([]) { |array, args| val, f = args; array << f unless val; array }
19+
result.zip(values).each_with_object([]) { |args, array| val, f = args; array << f unless val; }
2020
end
2121
end

lib/puppet/confine/variable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Puppet::Confine::Variable < Puppet::Confine
1212
# Only returns failed values, not all required values.
1313
def self.summarize(confines)
1414
result = Hash.new { |hash, key| hash[key] = [] }
15-
confines.inject(result) { |total, confine| total[confine.name] += confine.values unless confine.valid?; total }
15+
confines.each_with_object(result) { |confine, total| total[confine.name] += confine.values unless confine.valid?; }
1616
end
1717

1818
# This is set by ConfineCollection.

lib/puppet/face/epp.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,13 @@
180180
raise Puppet::Error, _("No input to parse given on command line or stdin")
181181
end
182182
else
183-
templates, missing_files = args.reduce([[], []]) do |memo, file|
183+
templates, missing_files = args.each_with_object([[], []]) do |file, memo|
184184
template_file = effective_template(file, compiler.environment)
185185
if template_file.nil?
186186
memo[1] << file
187187
else
188188
memo[0] << template_file
189189
end
190-
memo
191190
end
192191

193192
show_filename = templates.count > 1

lib/puppet/face/module/list.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ def unmet_dependencies(environment)
119119
# Prepare the unmet dependencies for display on the console.
120120
environment.modules.sort_by { |mod| mod.name }.each do |mod|
121121
unmet_grouped = Hash.new { |h, k| h[k] = [] }
122-
unmet_grouped = mod.unmet_dependencies.inject(unmet_grouped) do |acc, dep|
122+
unmet_grouped = mod.unmet_dependencies.each_with_object(unmet_grouped) do |dep, acc|
123123
acc[dep[:reason]] << dep
124-
acc
125124
end
126125
unmet_grouped.each do |type, deps|
127126
unless deps.empty?

lib/puppet/http/dns.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ def expired?(service_name)
146146
# @yields [[Resolv::DNS::Resource::IN::SRV]] a group of records of
147147
# the same priority
148148
def each_priority(records)
149-
pri_hash = records.inject({}) do |groups, element|
149+
pri_hash = records.each_with_object({}) do |element, groups|
150150
groups[element.priority] ||= []
151151
groups[element.priority] << element
152-
groups
153152
end
154153

155154
pri_hash.keys.sort.each do |key|

lib/puppet/indirector/node/exec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def create_node(name, result, facts = nil)
5454

5555
# Translate the yaml string into Ruby objects.
5656
def translate(name, output)
57-
Puppet::Util::Yaml.safe_load(output, [Symbol]).inject({}) do |hash, data|
57+
Puppet::Util::Yaml.safe_load(output, [Symbol]).each_with_object({}) do |data, hash|
5858
case data[0]
5959
when String
6060
hash[data[0].intern] = data[1]
@@ -63,8 +63,6 @@ def translate(name, output)
6363
else
6464
raise Puppet::Error, _("key is a %{klass}, not a string or symbol") % { klass: data[0].class }
6565
end
66-
67-
hash
6866
end
6967
rescue => detail
7068
raise Puppet::Error, _("Could not load external node results for %{name}: %{detail}") % { name: name, detail: detail }, detail.backtrace

lib/puppet/indirector/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def initialize(indirection_name, method, key, instance, options = {})
6868
self.indirection_name = indirection_name
6969
self.method = method
7070

71-
options = options.inject({}) { |hash, ary| hash[ary[0].to_sym] = ary[1]; hash }
71+
options = options.each_with_object({}) { |ary, hash| hash[ary[0].to_sym] = ary[1]; }
7272

7373
set_attributes(options)
7474

lib/puppet/network/http/handler.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,9 @@ def client_cert(request)
171171
end
172172

173173
def decode_params(params)
174-
params.select { |key, _| allowed_parameter?(key) }.inject({}) do |result, ary|
174+
params.select { |key, _| allowed_parameter?(key) }.each_with_object({}) do |ary, result|
175175
param, value = ary
176176
result[param.to_sym] = parse_parameter_value(param, value)
177-
result
178177
end
179178
end
180179

lib/puppet/parser/resource.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def set_parameter(param, value = nil)
216216
alias []= set_parameter
217217

218218
def to_hash
219-
parse_title.merge(@parameters.reduce({}) do |result, (_, param)|
219+
parse_title.merge(@parameters.each_with_object({}) do |(_, param), result|
220220
value = param.value
221221
value = (:undef == value) ? nil : value
222222

@@ -231,7 +231,6 @@ def to_hash
231231
result[param.name] = value
232232
end
233233
end
234-
result
235234
end)
236235
end
237236

0 commit comments

Comments
 (0)