Skip to content

Commit 7deaced

Browse files
dLobatogDominic Cleal
authored and
Dominic Cleal
committed
Refs theforeman#3809 - Style/blocks cop enabled
1 parent 4cd44e2 commit 7deaced

13 files changed

+68
-73
lines changed

.rubocop_todo.yml

-5
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ Style/AlignParameters:
136136
Style/AndOr:
137137
Enabled: false
138138

139-
# Offense count: 22
140-
# Cop supports --auto-correct.
141-
Style/Blocks:
142-
Enabled: false
143-
144139
# Offense count: 870
145140
# Cop supports --auto-correct.
146141
# Configuration parameters: EnforcedStyle, SupportedStyles.

app/controllers/api/base_controller.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ class BaseController < ActionController::Base
1717

1818
after_filter :log_response_body
1919

20-
rescue_from StandardError, :with => lambda { |error|
20+
rescue_from StandardError do |error|
2121
Foreman::Logging.exception("Action failed", error)
2222
render_error 'standard_error', :status => :internal_server_error, :locals => { :exception => error }
23-
}
23+
end
2424

25-
rescue_from ScopedSearch::QueryNotSupported, Apipie::ParamError, :with => lambda { |error|
25+
rescue_from ScopedSearch::QueryNotSupported, Apipie::ParamError do |error|
2626
logger.info "#{error.message} (#{error.class})"
2727
render_error 'param_error', :status => :bad_request, :locals => { :exception => error }
28-
}
28+
end
2929

30-
rescue_from ActiveRecord::RecordNotFound, :with => lambda { |error|
30+
rescue_from ActiveRecord::RecordNotFound do |error|
3131
logger.info "#{error.message} (#{error.class})"
3232
not_found
33-
}
33+
end
3434

3535
def get_resource
3636
instance_variable_get :"@#{resource_name}" or raise 'no resource loaded'

app/controllers/hosts_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ def index(title = nil)
5252

5353
def show
5454
respond_to do |format|
55-
format.html {
55+
format.html do
5656
# filter graph time range
5757
@range = (params["range"].empty? ? 7 : params["range"].to_i)
5858

5959
# summary report text
6060
@report_summary = Report.summarise(@range.days.ago, @host)
61-
}
61+
end
6262
format.yaml { render :text => @host.info.to_yaml }
6363
format.json
6464
end

app/helpers/compute_resources_vms_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ def default_available_actions(vm, authorizer = nil)
116116

117117
def vpc_security_group_hash(security_groups)
118118
vpc_sg_hash = {}
119-
security_groups.each{ |sg|
119+
security_groups.each do |sg|
120120
vpc_id = sg.vpc_id || 'ec2'
121121
( vpc_sg_hash[vpc_id] ||= []) << {:group_name => sg.name, :group_id => sg.group_id}
122-
}
122+
end
123123
vpc_sg_hash
124124
end
125125

app/models/environment.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def puppetEnvs(proxy = nil)
3838
url = (proxy || SmartProxy.with_features("Puppet").first).try(:url)
3939
raise ::Foreman::Exception.new(N_("Can't find a valid Foreman Proxy with a Puppet feature")) if url.blank?
4040
proxy = ProxyAPI::Puppet.new :url => url
41-
HashWithIndifferentAccess[proxy.environments.map { |e|
42-
[e, HashWithIndifferentAccess[proxy.classes(e).map {|k|
41+
HashWithIndifferentAccess[proxy.environments.map do |e|
42+
[e, HashWithIndifferentAccess[proxy.classes(e).map do |k|
4343
klass = k.keys.first
4444
[klass, k[klass]["params"]]
45-
}]]
46-
}]
45+
end]]
46+
end]
4747
end
4848
end
4949
end

app/models/environment_class.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class EnvironmentClass < ActiveRecord::Base
2121
}
2222

2323
# These counters key track of unique puppet class keys (parameters) across environments
24-
after_create { |record|
24+
after_create do |record|
2525
Puppetclass.increment_counter(:global_class_params_count, self.puppetclass.id) unless self.lookup_key.blank? ||
2626
EnvironmentClass.used_by_other_environment_classes(self.lookup_key, self.id).count > 0
27-
}
27+
end
2828

29-
after_destroy { |record|
29+
after_destroy do |record|
3030
Puppetclass.decrement_counter(:global_class_params_count, self.puppetclass.id) unless self.lookup_key.blank? ||
3131
EnvironmentClass.used_by_other_environment_classes(self.lookup_key, self.id).count > 0
32-
}
32+
end
3333

3434
#TODO move these into scopes?
3535
def self.is_in_any_environment(puppetclass, lookup_key)

app/models/taxonomy.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ def self.enabled_taxonomies
8484
end
8585

8686
def self.ignore?(taxable_type)
87-
Array.wrap(self.current).each{ |current|
87+
Array.wrap(self.current).each do |current|
8888
return true if current.ignore?(taxable_type)
89-
}
89+
end
9090
false
9191
end
9292

app/services/dashboard/manager.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def self.add_widget_to_user(user, widget)
2323

2424
def self.reset_user_to_default(user)
2525
user.widgets.clear
26-
@default_widgets.each {|widget|
26+
@default_widgets.each do |widget|
2727
add_widget_to_user(user, widget)
28-
}
28+
end
2929
end
3030
end
3131
end

db/migrate/20100524080302_migrate_installation_medium_uri.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
class MigrateInstallationMediumUri < ActiveRecord::Migration
22
def up
3-
Medium.unscoped.all.each { |medium|
3+
Medium.unscoped.all.each do |medium|
44
matches = /^([^:]+):(\/.+)/.match(medium.path)
55

66
if matches.size == 3 and ![ 'http', 'https', 'ftp', 'ftps', 'nfs' ].include?(matches[1])
77
medium.path = 'nfs://' + matches[1] + matches[2]
88
medium.save
99
end
10-
}
10+
end
1111
end
1212

1313
def down

db/migrate/20141021105446_rename_subnet_name_to_unique.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ def up
33
multiple_same_name = Subnet.unscoped.group(:name).count.delete_if {|name, value| value == 1}
44
multiple_same_name.each_key do | subnet_name |
55
subnets_with_same_name = Subnet.where(:name => subnet_name)
6-
subnets_with_same_name.each_with_index { |subnet, index |
6+
subnets_with_same_name.each_with_index do |subnet, index |
77
new_name = Subnet.exists?(:name => "#{subnet.name}-#{index}") ? "#{subnet.name}-#{index}-#{SecureRandom.hex(2)}" : "#{subnet.name}-#{index}"
88
subnet.update_attribute(:name, new_name)
9-
}
9+
end
1010
end
1111
end
1212
end

test/factories/auth_source_ldap.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
server_type 'posix'
1111
end
1212

13-
trait :posix do end
13+
trait :posix
1414

1515
trait :free_ipa do
1616
server_type 'free_ipa'

test/factories/host_related.rb

+39-39
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def set_nic_attributes(host, attributes, evaluator)
5151
sequence(:mac) { |n| "00:00:00:00:" + n.to_s(16).rjust(4, '0').insert(2, ':') }
5252

5353
trait :with_subnet do
54-
subnet {
54+
subnet do
5555
FactoryGirl.build(:subnet,
5656
:organizations => host ? [host.organization] : [],
5757
:locations => host ? [host.location] : [])
58-
}
58+
end
5959
end
6060
end
6161

@@ -183,9 +183,9 @@ def set_nic_attributes(host, attributes, evaluator)
183183

184184
trait :with_puppet do
185185
environment
186-
puppet_proxy { FactoryGirl.create(:smart_proxy,
187-
:features => [FactoryGirl.create(:feature, :puppet)])
188-
}
186+
puppet_proxy do
187+
FactoryGirl.create(:smart_proxy, :features => [FactoryGirl.create(:feature, :puppet)])
188+
end
189189
end
190190

191191
trait :managed do
@@ -204,7 +204,7 @@ def set_nic_attributes(host, attributes, evaluator)
204204
managed
205205
association :compute_resource, :factory => :libvirt_cr
206206
domain
207-
subnet {
207+
subnet do
208208
overrides = {
209209
:dhcp => FactoryGirl.create(:smart_proxy,
210210
:features => [FactoryGirl.create(:feature, :dhcp)])
@@ -216,36 +216,36 @@ def set_nic_attributes(host, attributes, evaluator)
216216
:subnet,
217217
overrides
218218
)
219-
}
220-
interfaces { [ FactoryGirl.build(:nic_primary_and_provision,
221-
:ip => subnet.network.sub(/0\Z/, '1')) ]
222-
}
219+
end
220+
interfaces do
221+
[FactoryGirl.build(:nic_primary_and_provision, :ip => subnet.network.sub(/0\Z/, '1'))]
222+
end
223223
end
224224

225225
trait :with_dns_orchestration do
226226
managed
227227
association :compute_resource, :factory => :libvirt_cr
228-
subnet {
228+
subnet do
229229
overrides = {:dns => FactoryGirl.create(:smart_proxy,
230230
:features => [FactoryGirl.create(:feature, :dns)])}
231231
#add taxonomy overrides in case it's set in the host object
232232
overrides[:locations] = [location] unless location.nil?
233233
overrides[:organizations] = [organization] unless organization.nil?
234234

235235
FactoryGirl.create(:subnet, overrides)
236-
}
237-
domain {
236+
end
237+
domain do
238238
FactoryGirl.create(:domain,
239239
:dns => FactoryGirl.create(:smart_proxy,
240240
:features => [FactoryGirl.create(:feature, :dns)])
241241
)
242-
}
243-
interfaces { [ FactoryGirl.build(:nic_managed,
244-
:primary => true,
245-
:provision => true,
246-
:domain => FactoryGirl.build(:domain),
247-
:ip => subnet.network.sub(/0\Z/, '1')) ]
248-
}
242+
end
243+
interfaces do
244+
[FactoryGirl.build(:nic_managed, :primary => true,
245+
:provision => true,
246+
:domain => FactoryGirl.build(:domain),
247+
:ip => subnet.network.sub(/0\Z/, '1'))]
248+
end
249249
end
250250

251251
trait :with_tftp_subnet do
@@ -255,13 +255,13 @@ def set_nic_attributes(host, attributes, evaluator)
255255
trait :with_tftp_orchestration do
256256
managed
257257
with_tftp_subnet
258-
interfaces { [ FactoryGirl.build(:nic_managed,
259-
:primary => true,
260-
:provision => true,
261-
:domain => FactoryGirl.build(:domain),
262-
:subnet => subnet,
263-
:ip => subnet.network.sub(/0\Z/, '2')) ]
264-
}
258+
interfaces do
259+
[FactoryGirl.build(:nic_managed, :primary => true,
260+
:provision => true,
261+
:domain => FactoryGirl.build(:domain),
262+
:subnet => subnet,
263+
:ip => subnet.network.sub(/0\Z/, '2'))]
264+
end
265265
end
266266

267267
trait :with_puppet_orchestration do
@@ -270,9 +270,9 @@ def set_nic_attributes(host, attributes, evaluator)
270270
association :compute_resource, :factory => :libvirt_cr
271271
domain
272272
interfaces { [ FactoryGirl.build(:nic_primary_and_provision) ] }
273-
puppet_ca_proxy { FactoryGirl.create(:smart_proxy,
274-
:features => [FactoryGirl.create(:feature, :puppetca)])
275-
}
273+
puppet_ca_proxy do
274+
FactoryGirl.create(:smart_proxy, :features => [FactoryGirl.create(:feature, :puppetca)])
275+
end
276276
end
277277

278278
trait :with_realm do
@@ -321,15 +321,15 @@ def set_nic_attributes(host, attributes, evaluator)
321321
trait :with_puppet_orchestration do
322322
architecture
323323
ptable
324-
operatingsystem { FactoryGirl.create(:operatingsystem,
325-
:architectures => [architecture], :ptables => [ptable] )
326-
}
327-
puppet_ca_proxy { FactoryGirl.create(:smart_proxy,
328-
:features => [FactoryGirl.create(:feature, :puppetca)])
329-
}
330-
puppet_proxy { FactoryGirl.create(:smart_proxy,
331-
:features => [FactoryGirl.create(:feature, :puppet)])
332-
}
324+
operatingsystem do
325+
FactoryGirl.create(:operatingsystem, :architectures => [architecture], :ptables => [ptable])
326+
end
327+
puppet_ca_proxy do
328+
FactoryGirl.create(:smart_proxy, :features => [FactoryGirl.create(:feature, :puppetca)])
329+
end
330+
puppet_proxy do
331+
FactoryGirl.create(:smart_proxy, :features => [FactoryGirl.create(:feature, :puppet)])
332+
end
333333
end
334334
end
335335
end

test/factories/operatingsystem.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
end
1616

1717
trait :with_provision do
18-
provisioning_templates {
18+
provisioning_templates do
1919
[FactoryGirl.create(:provisioning_template, :template_kind => TemplateKind.find_by_name('provision'))]
20-
}
20+
end
2121
with_os_defaults
2222
end
2323

0 commit comments

Comments
 (0)