From 382311abd1259940c061222a26c2a0cd6fcf5e2d Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Wed, 7 Sep 2016 12:57:07 -0400 Subject: [PATCH] Don't use interpolation if it's not required. Follow up to #11074, but for the core backend ruby files Interpolation syntax can be error prone so don't use it when you can just convert to string. Prefer `variable.to_s` over `"#{variable}"` Also, some places we use Array#join which returns a String already: `"#{rate_detail.errors.full_messages.join(', ')}"` Becomes: `rate_detail.errors.full_messages.join(', ')` Also, some places already created a message string but then wanted to interpolate it for good measure: ```diff msg = "Authentication failed for userid #{username}, unable to find user object in #{self.class.proper_name}" - _log.warn("#{msg}") + _log.warn(msg) ``` rubocop -a --only "Lint/StringConversionInInterpolation,Style/UnneededInterpolation" ... (transferred from ManageIQ/manageiq@62e49805f8cc9a188e23a18b8c69bfd73479485a) --- lib/miq_automation_engine/engine/miq_ae_engine.rb | 10 +++++----- lib/miq_automation_engine/models/miq_ae_method_yaml.rb | 2 +- .../service_models/miq_ae_service_methods.rb | 2 +- .../mixins/miq_ae_service_miq_provision_mixin.rb | 2 +- spec/miq_ae_object_spec.rb | 2 +- ..._manageiq-providers-cloud_manager-provision_spec.rb | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/miq_automation_engine/engine/miq_ae_engine.rb b/lib/miq_automation_engine/engine/miq_ae_engine.rb index 461656f06..fa0957468 100644 --- a/lib/miq_automation_engine/engine/miq_ae_engine.rb +++ b/lib/miq_automation_engine/engine/miq_ae_engine.rb @@ -119,7 +119,7 @@ def self.deliver(*args) if ws.nil? || ws.root.nil? message = "Error delivering #{options[:attrs].inspect} for object [#{object_name}] with state [#{state}] to Automate: Empty Workspace" - _log.error("#{message}") + _log.error(message) return nil end @@ -138,12 +138,12 @@ def self.deliver(*args) options[:ae_state_previous] = YAML.dump(ws.current_state_info) unless ws.current_state_info.empty? message = "Requeuing #{options.inspect} for object [#{object_name}] with state [#{options[:state]}] to Automate for delivery in [#{ae_retry_interval}] seconds" - _log.info("#{message}") + _log.info(message) deliver_queue(options, :deliver_on => deliver_on) else if ae_result.casecmp('error').zero? message = "Error delivering #{options[:attrs].inspect} for object [#{object_name}] with state [#{state}] to Automate: #{ws.root['ae_message']}" - _log.error("#{message}") + _log.error(message) end MiqAeEvent.process_result(ae_result, automate_attrs) if options[:instance_name].to_s.casecmp('EVENT').zero? end @@ -152,7 +152,7 @@ def self.deliver(*args) return ws rescue MiqAeException::Error => err message = "Error delivering #{automate_attrs.inspect} for object [#{object_name}] with state [#{state}] to Automate: #{err.message}" - _log.error("#{message}") + _log.error(message) ensure vmdb_object.after_ae_delivery(ae_result.to_s.downcase) if vmdb_object.respond_to?(:after_ae_delivery) end @@ -212,7 +212,7 @@ def self.create_automation_attribute_name(object) def self.create_automation_attribute_key(object, attr_name = nil) klass_name = create_automation_attribute_class_name(object) - return "#{klass_name}" if automation_attribute_is_array?(klass_name) + return klass_name.to_s if automation_attribute_is_array?(klass_name) attr_name ||= create_automation_attribute_name(object) "#{klass_name}::#{attr_name}" end diff --git a/lib/miq_automation_engine/models/miq_ae_method_yaml.rb b/lib/miq_automation_engine/models/miq_ae_method_yaml.rb index 8a90055e3..5ff0e1a78 100644 --- a/lib/miq_automation_engine/models/miq_ae_method_yaml.rb +++ b/lib/miq_automation_engine/models/miq_ae_method_yaml.rb @@ -10,7 +10,7 @@ def initialize(filename = nil) def define_instance_variables @ae_method_obj['object']['attributes'].each do |k, v| instance_variable_set("@#{k}", v) - singleton_class.class_eval { attr_accessor "#{k}" } + singleton_class.class_eval { attr_accessor k.to_s } send("#{k}=", v) end end diff --git a/lib/miq_automation_engine/service_models/miq_ae_service_methods.rb b/lib/miq_automation_engine/service_models/miq_ae_service_methods.rb index d0e2c9381..14dbc9fb1 100644 --- a/lib/miq_automation_engine/service_models/miq_ae_service_methods.rb +++ b/lib/miq_automation_engine/service_models/miq_ae_service_methods.rb @@ -121,7 +121,7 @@ def self.service_now_eccq_insert(server, username, password, agent, queue, topic $log.error hserr.backtrace.join("\n") raise rescue => err - _log.error "#{err}" + _log.error err.to_s $log.error err.backtrace.join("\n") raise end diff --git a/lib/miq_automation_engine/service_models/mixins/miq_ae_service_miq_provision_mixin.rb b/lib/miq_automation_engine/service_models/mixins/miq_ae_service_miq_provision_mixin.rb index a25c36f45..fe0297d3f 100644 --- a/lib/miq_automation_engine/service_models/mixins/miq_ae_service_miq_provision_mixin.rb +++ b/lib/miq_automation_engine/service_models/mixins/miq_ae_service_miq_provision_mixin.rb @@ -57,7 +57,7 @@ def set_dvs(portgroup, switch = portgroup) end def set_vlan(vlan) - set_option(:vlan, ["#{vlan}", "#{vlan}"]) + set_option(:vlan, [vlan.to_s, vlan.to_s]) end def get_folder_paths diff --git a/spec/miq_ae_object_spec.rb b/spec/miq_ae_object_spec.rb index b8e557fe3..9b515fc0a 100644 --- a/spec/miq_ae_object_spec.rb +++ b/spec/miq_ae_object_spec.rb @@ -63,7 +63,7 @@ def value_match(value, xml_value) end it "#process_args_as_attributes with a hash with an object reference" do - result = @miq_obj.process_args_as_attributes("VmOrTemplate::vm" => "#{@vm.id}") + result = @miq_obj.process_args_as_attributes("VmOrTemplate::vm" => @vm.id.to_s) expect(result["vm_id"]).to eq(@vm.id.to_s) expect(result["vm"]).to be_kind_of(MiqAeMethodService::MiqAeServiceVmOrTemplate) end diff --git a/spec/service_methods/miq_ae_service_manageiq-providers-cloud_manager-provision_spec.rb b/spec/service_methods/miq_ae_service_manageiq-providers-cloud_manager-provision_spec.rb index b224af25e..60bd7e90b 100644 --- a/spec/service_methods/miq_ae_service_manageiq-providers-cloud_manager-provision_spec.rb +++ b/spec/service_methods/miq_ae_service_manageiq-providers-cloud_manager-provision_spec.rb @@ -35,7 +35,7 @@ module MiqAeServiceManageIQ_Providers_CloudManager_ProvisionSpec end %w(template clone_to_vm).each do |provision_type| - it "#{provision_type}" do + it provision_type.to_s do @miq_provision.update_attributes(:provision_type => provision_type) expect(ae_svc_prov.target_type).to eq('vm') end