Skip to content

Commit

Permalink
Refs #29172 - Fix Layout/SpaceInsideBlockBraces cop
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoll authored and lzap committed Feb 28, 2020
1 parent 7b0a46e commit 5c3194e
Show file tree
Hide file tree
Showing 60 changed files with 168 additions and 176 deletions.
8 changes: 0 additions & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ Layout/SpaceAroundOperators:
Layout/SpaceInsideArrayLiteralBrackets:
Enabled: false

# Offense count: 326
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
Enabled: false

# Offense count: 419
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
Expand Down
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ $LOAD_PATH.unshift *Dir[File.expand_path("../lib", __FILE__), File.expand_path("

require 'smart_proxy_main'
::Proxy::PluginInitializer.new(::Proxy::Plugins.instance).initialize_plugins
::Proxy::Plugins.instance.select {|p| p[:state] == :running && p[:https_enabled]}.each {|p| instance_eval(p[:class].https_rackup)}
::Proxy::Plugins.instance.select { |p| p[:state] == :running && p[:https_enabled] }.each { |p| instance_eval(p[:class].https_rackup) }
6 changes: 3 additions & 3 deletions extra/dhcpd_config_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def parse_cli_options(args)
options = parse_cli_options(ARGV)
parser = ::Proxy::DHCP::CommonISC::ConfigurationParser.new
subnets, hosts, _, ignored = parser.subnets_hosts_and_leases(File.read(options[:cfg_path]), options[:cfg_path])
puts "Subnets: %s" % [subnets.map {|s| "#{s.subnet_address}/#{s.subnet_mask}"}.join(', ')]
puts "Hosts and leases: %s" % [hosts.map {|h| h.respond_to?(:ip_address) ? "Lease: #{h.ip_address}" : "Host: #{h.name}"}.join(', ')]
puts "Didn't recognize: \n%s" % [ignored.map {|i| "#{i.content}, parents: #{i.parents.join(', ')}"}.join("\n")]
puts "Subnets: %s" % [subnets.map { |s| "#{s.subnet_address}/#{s.subnet_mask}" }.join(', ')]
puts "Hosts and leases: %s" % [hosts.map { |h| h.respond_to?(:ip_address) ? "Lease: #{h.ip_address}" : "Host: #{h.name}" }.join(', ')]
puts "Didn't recognize: \n%s" % [ignored.map { |i| "#{i.content}, parents: #{i.parents.join(', ')}" }.join("\n")]
rescue OptionParser::InvalidOption, OptionParser:: MissingArgument, MissingOption
exit(1)
rescue RuntimeError => e
Expand Down
4 changes: 2 additions & 2 deletions extra/migrate_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def register_migration(migration_class)

def new_migrations
# don't want to deal with namespaced constant resolution/loading
migrations.select {|m| !past_migrations.include?(m.name) }
migrations.select { |m| !past_migrations.include?(m.name) }
end

def persist_migrations_state(migrations, result_dir_path)
Expand Down Expand Up @@ -179,7 +179,7 @@ def copy_migration_results_to_results_dir(results_dir)
end

def persist_migrations_state(migrations, path)
@migrations.persist_migrations_state(migrations.map {|m| m.class.name}, path)
@migrations.persist_migrations_state(migrations.map { |m| m.class.name }, path)
rescue Exception => e
p "Couldn't save migration state: #{e}"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def known_options

def migrate_monolithic_config(data)
output = {}
modules.each {|m| output[m] = {} }
modules.each { |m| output[m] = {} }

# chef's enabler got called something non-standard...
data[:chef] = data.delete(:chefproxy) unless data[:chefproxy].nil?
Expand Down
4 changes: 2 additions & 2 deletions extra/migrations/20160413000000_migrate_puppet_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def remap_parameter(aparameter, avalue)
module_names = module_names_to_parameter[0..-2]

avalue = old_provider_name_to_new(avalue) if parameter_name == :use_provider
module_names.map {|module_name| [module_name, parameter_name, avalue]}
module_names.map { |module_name| [module_name, parameter_name, avalue] }
end

def old_provider_name_to_new(aname)
Expand All @@ -54,7 +54,7 @@ def old_provider_name_to_new(aname)
def migrate_puppet_configuration(to_migrate)
migrated = Hash.new { |h, k| h[k] = Hash.new }
to_migrate.each do |option, value|
remap_parameter(option, value).each {|module_name, parameter_name, parameter_value| migrated[module_name][parameter_name] = parameter_value}
remap_parameter(option, value).each { |module_name, parameter_name, parameter_value| migrated[module_name][parameter_name] = parameter_value }
end

# deal with puppet_user setting, which used to be global, but has been moved (and renamed) to puppetrun and mcollective modules
Expand Down
6 changes: 3 additions & 3 deletions extra/register-service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

puts "This service must be run under an account that is a member of 'DHCP Administrators' group"
puts 'The account can be local or a domain account. If it is a domain account then use the domain\account syntax'
service_name = ask("Enter the name of the service. ") {|s| s.default = default_service_name}
user = ask("Enter the user to run the service as: ") {|u| u.default = default_user}
pass1 = ask("Enter the user's password. ") {|p| p.echo = "x"}
service_name = ask("Enter the name of the service. ") { |s| s.default = default_service_name }
user = ask("Enter the user to run the service as: ") { |u| u.default = default_user }
pass1 = ask("Enter the user's password. ") { |p| p.echo = "x" }

description = 'Foreman Smart Proxy'
description += " (#{service_name})" unless service_name == default_service_name
Expand Down
4 changes: 2 additions & 2 deletions lib/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def check_pid

def write_pid
FileUtils.mkdir_p(File.dirname(pid_path)) unless File.exist?(pid_path)
File.open(pid_path, ::File::CREAT | ::File::EXCL | ::File::WRONLY) {|f| f.write(Process.pid.to_s) }
File.open(pid_path, ::File::CREAT | ::File::EXCL | ::File::WRONLY) { |f| f.write(Process.pid.to_s) }
at_exit { File.delete(pid_path) if File.exist?(pid_path) }
rescue Errno::EEXIST
check_pid
Expand All @@ -148,7 +148,7 @@ def write_pid

def webrick_server(app, addresses, port)
server = ::WEBrick::HTTPServer.new(app)
addresses.each {|a| server.listen(a, port)}
addresses.each { |a| server.listen(a, port) }
server.mount "/", Rack::Handler::WEBrick, app[:app]
server
end
Expand Down
2 changes: 1 addition & 1 deletion lib/proxy/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def call(env)
status = 500
env['rack.logger'] = logger
logger.info { "Started #{env['REQUEST_METHOD']} #{env['REQUEST_PATH']} #{env['QUERY_STRING']}" }
logger.trace { 'Headers: ' + env.select {|k, v| k.start_with? 'HTTP_'}.inspect }
logger.trace { 'Headers: ' + env.select { |k, v| k.start_with? 'HTTP_' }.inspect }
logger.trace do
if env['rack.input'] && !(body = env['rack.input'].read).empty?
env['rack.input'].rewind
Expand Down
2 changes: 1 addition & 1 deletion lib/proxy/log_buffer/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Proxy::LogBuffer
LogRecord = Struct.new(:timestamp, :level, :message, :backtrace, :request_id) do
def to_h
h = {}
self.class.members.each {|m| h[m.to_sym] = self[m]}
self.class.members.each { |m| h[m.to_sym] = self[m] }
h[:level] = case h[:level]
when ::Logger::Severity::INFO
:INFO
Expand Down
2 changes: 1 addition & 1 deletion lib/proxy/pluggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def validate(*settings)
validator_name = validator_params.keys.first
validator_args = validator_params[validator_name]

settings.each {|setting| validations << {:name => validator_name, :predicate => predicate, :args => validator_args, :setting => setting} }
settings.each { |setting| validations << {:name => validator_name, :predicate => predicate, :args => validator_args, :setting => setting} }
end

def override_module_loader_class(a_class_or_a_class_name)
Expand Down
34 changes: 17 additions & 17 deletions lib/proxy/plugin_initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def resolve_providers(all_plugins_and_providers)
return unless @plugin.uses_provider?

used_providers = [@plugin.settings.use_provider].flatten.map(&:to_sym)
providers = all_plugins_and_providers.select {|p| used_providers.include?(p[:name].to_sym)}
providers = all_plugins_and_providers.select { |p| used_providers.include?(p[:name].to_sym) }

not_available = used_providers - providers.map {|p| p[:name].to_sym}
not_available = used_providers - providers.map { |p| p[:name].to_sym }

if not_available.empty?
logger.debug "Providers #{printable_module_names(used_providers)} are going to be configured for '#{@plugin.plugin_name}'"
return @providers = providers.map {|p| p[:class]}
return @providers = providers.map { |p| p[:class] }
end

fail_group_with_message("Disabling all modules in the group #{printable_module_names(member_names)}: following providers are not available #{printable_module_names(not_available)}")
Expand All @@ -72,7 +72,7 @@ def member_names
end

def printable_module_names(names)
printable = names.map {|name| "'#{name}'"}.join(", ")
printable = names.map { |name| "'#{name}'" }.join(", ")
"[#{printable}]"
end

Expand Down Expand Up @@ -106,7 +106,7 @@ def load_provider_settings

def configure
return if inactive?
members.each {|p| p.module_loader_class.new(p, di_container).configure_plugin }
members.each { |p| p.module_loader_class.new(p, di_container).configure_plugin }
@state = :running
rescue Exception => e
stop_services
Expand All @@ -127,12 +127,12 @@ def fail_group_with_message(a_message, an_exception = nil)

def stop_services
members.each do |member|
member.services.map {|label| di_container.get_dependency(label)}.each {|service| service.stop if service.respond_to?(:stop)}
member.services.map { |label| di_container.get_dependency(label) }.each { |service| service.stop if service.respond_to?(:stop) }
end
end

def validate_dependencies_or_fail(enabled_providers_and_plugins)
members.each {|p| validate_dependencies!(p, p.dependencies, enabled_providers_and_plugins)}
members.each { |p| validate_dependencies!(p, p.dependencies, enabled_providers_and_plugins) }
rescue Exception => e
stop_services
fail_group(e)
Expand All @@ -157,9 +157,9 @@ def initialize(plugins)
end

def initialize_plugins
loaded_plugins = plugins.loaded.select {|plugin| plugin[:class].ancestors.include?(::Proxy::Plugin)}
loaded_plugins = plugins.loaded.select { |plugin| plugin[:class].ancestors.include?(::Proxy::Plugin) }

grouped_with_providers = loaded_plugins.map {|p| ::Proxy::PluginGroup.new(p[:class], [], Proxy::DependencyInjection::Container.new)}
grouped_with_providers = loaded_plugins.map { |p| ::Proxy::PluginGroup.new(p[:class], [], Proxy::DependencyInjection::Container.new) }

plugins.update(current_state_of_modules(plugins.loaded, grouped_with_providers))

Expand All @@ -169,7 +169,7 @@ def initialize_plugins
plugins.update(current_state_of_modules(plugins.loaded, grouped_with_providers))

# resolve provider names to classes
grouped_with_providers.each {|group| group.resolve_providers(plugins.loaded)}
grouped_with_providers.each { |group| group.resolve_providers(plugins.loaded) }

# validate prerequisite versions and availability
all_enabled = all_enabled_plugins_and_providers(grouped_with_providers)
Expand Down Expand Up @@ -200,15 +200,15 @@ def current_state_of_modules(all_plugins, all_groups)
to_update = all_plugins.dup
all_groups.each do |group|
# note that providers do not use http_enabled and https_enabled
updated = to_update.find {|loaded_plugin| loaded_plugin[:name] == group.plugin.plugin_name}
updated = to_update.find { |loaded_plugin| loaded_plugin[:name] == group.plugin.plugin_name }
updated[:di_container] = group.di_container
updated[:state] = group.state
updated[:http_enabled] = group.http_enabled?
updated[:https_enabled] = group.https_enabled?
updated[:capabilities] = group.capabilities
updated[:settings] = group.exposed_settings
group.providers.each do |group_member|
updated = to_update.find {|loaded_plugin| loaded_plugin[:name] == group_member.plugin_name}
updated = to_update.find { |loaded_plugin| loaded_plugin[:name] == group_member.plugin_name }
updated[:di_container] = group.di_container
updated[:state] = group.state
end
Expand All @@ -218,7 +218,7 @@ def current_state_of_modules(all_plugins, all_groups)

def all_enabled_plugins_and_providers(all_groups)
all_groups.inject({}) do |all, group|
group.members.each {|p| all[p.plugin_name] = p} unless group.inactive?
group.members.each { |p| all[p.plugin_name] = p } unless group.inactive?
all
end
end
Expand Down Expand Up @@ -261,11 +261,11 @@ def start_services(services, container)

module ::Proxy::DefaultSettingsLoader
def load_plugin_settings
load_settings({}) {|s| log_used_settings(s)}
load_settings({}) { |s| log_used_settings(s) }
end

def load_provider_settings(main_plugin_settings)
load_settings(main_plugin_settings) {|s| log_provider_settings(s)}
load_settings(main_plugin_settings) { |s| log_provider_settings(s) }
end

def load_settings(main_plugin_settings)
Expand Down Expand Up @@ -325,7 +325,7 @@ def log_used_settings(settings)
def log_provider_settings(settings)
default_settings = plugin.plugin_default_settings
sorted_keys = settings.keys.map(&:to_s).sort.map(&:to_sym) # ruby 1.8.7 doesn't support sorting of symbols
to_log = sorted_keys.map {|k| "'%s': %s%s" % [k, settings[k], (default_settings.include?(k) && default_settings[k] == settings[k]) ? " (default)" : ""] }.join(", ")
to_log = sorted_keys.map { |k| "'%s': %s%s" % [k, settings[k], (default_settings.include?(k) && default_settings[k] == settings[k]) ? " (default)" : ""] }.join(", ")
logger.debug "'%s' settings: %s" % [plugin.plugin_name, to_log]
end

Expand All @@ -339,7 +339,7 @@ def load_classes
end

def validate_settings(plugin, config)
result = execute_validators(plugin.plugin_default_settings.keys.map {|k| {:name => :presence, :setting => k}}, config)
result = execute_validators(plugin.plugin_default_settings.keys.map { |k| {:name => :presence, :setting => k} }, config)
result + execute_validators(plugin.validations, config)
end

Expand Down
10 changes: 5 additions & 5 deletions lib/proxy/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def loaded

def update(updated_plugins)
updated_plugins.each do |updated|
loaded.delete_if {|p| p[:name] == updated[:name]}
loaded.delete_if { |p| p[:name] == updated[:name] }
loaded << updated
end
end
Expand All @@ -56,11 +56,11 @@ def select
#

def enabled_plugins
loaded.select {|p| p[:state] == :running && p[:class].ancestors.include?(::Proxy::Plugin)}.map {|p| p[:class]}
loaded.select { |p| p[:state] == :running && p[:class].ancestors.include?(::Proxy::Plugin) }.map { |p| p[:class] }
end

def plugin_enabled?(plugin_name)
plugin = loaded.find {|p| p[:name] == plugin_name.to_sym}
plugin = loaded.find { |p| p[:name] == plugin_name.to_sym }
plugin.nil? ? false : plugin[:state] == :running
end

Expand All @@ -70,7 +70,7 @@ def self.disable_plugin(plugin_name)

def disable_plugin(plugin_name)
logger.warn("::Proxy::Plugins.disable_plugin has been deprecated and will be removed from future versions of smart-proxy. Use Proxy::Pluggable#loading_failed instead.")
plugin = loaded.find {|p| p[:name] == plugin_name.to_sym}
plugin = loaded.find { |p| p[:name] == plugin_name.to_sym }
plugin[:class].fail
end

Expand All @@ -80,7 +80,7 @@ def find_plugin(plugin_name)
end

def find_provider(provider_name)
provider = loaded.find {|p| p[:name] == provider_name.to_sym}
provider = loaded.find { |p| p[:name] == provider_name.to_sym }
raise ::Proxy::PluginProviderNotFound, "Provider '#{provider_name}' could not be found" if provider.nil? || !provider[:class].ancestors.include?(::Proxy::Provider)
provider[:class]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/proxy/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(base_uri)
end

def query_string(input={})
input.compact.map {|k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v)}"}.join("&")
input.compact.map { |k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v)}" }.join("&")
end

def create_get(path, query={}, headers={})
Expand Down
2 changes: 1 addition & 1 deletion modules/dhcp/dependency_injection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Proxy::DHCP
module DependencyInjection
include Proxy::DependencyInjection::Accessors
def container_instance
@container_instance ||= ::Proxy::Plugins.instance.find {|p| p[:name] == :dhcp }[:di_container]
@container_instance ||= ::Proxy::Plugins.instance.find { |p| p[:name] == :dhcp }[:di_container]
end
end
end
2 changes: 1 addition & 1 deletion modules/dhcp/dhcp_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Proxy::DhcpApi < ::Sinatra::Base

get "/?" do
content_type :json
server.subnets.map {|s| {:network => s.network, :netmask => s.netmask, :options => s.options}}.to_json
server.subnets.map { |s| {:network => s.network, :netmask => s.netmask, :options => s.options} }.to_json
rescue => e
log_halt 400, e
end
Expand Down
Loading

0 comments on commit 5c3194e

Please sign in to comment.