From db3dfdcb78bffd25567703cd2203e841bfea2877 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Tue, 10 Jan 2017 15:29:59 +1030 Subject: [PATCH] Rubocop: if/unless modifier --- .rubocop_todo.yml | 13 ------------- app/models/entities/lead.rb | 12 +++--------- app/models/entities/opportunity.rb | 8 ++------ app/models/setting.rb | 8 ++------ db/migrate/20100928030620_remove_uuid.rb | 4 +--- lib/fat_free_crm.rb | 4 +--- lib/fat_free_crm/mail_processor/base.rb | 4 +--- lib/tasks/ffcrm/update_data.rake | 4 +--- 8 files changed, 11 insertions(+), 46 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3e8829c60b..fe263b5c5d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -424,19 +424,6 @@ Style/IdenticalConditionalBranches: Exclude: - 'app/helpers/application_helper.rb' -# Offense count: 11 -# Cop supports --auto-correct. -# Configuration parameters: MaxLineLength. -Style/IfUnlessModifier: - Exclude: - - 'app/models/entities/lead.rb' - - 'app/models/entities/opportunity.rb' - - 'app/models/setting.rb' - - 'db/migrate/20100928030620_remove_uuid.rb' - - 'lib/fat_free_crm.rb' - - 'lib/fat_free_crm/mail_processor/base.rb' - - 'lib/tasks/ffcrm/update_data.rake' - # Offense count: 27 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/app/models/entities/lead.rb b/app/models/entities/lead.rb index a0b0082114..a40aa01a9d 100644 --- a/app/models/entities/lead.rb +++ b/app/models/entities/lead.rb @@ -151,9 +151,7 @@ def reject # Attach a task to the lead if it hasn't been attached already. #---------------------------------------------------------------------------- def attach!(task) - unless task_ids.include?(task.id) - tasks << task - end + tasks << task unless task_ids.include?(task.id) end # Discard a task from the lead. @@ -176,16 +174,12 @@ def full_name(format = nil) #---------------------------------------------------------------------------- def increment_leads_count - if campaign_id - Campaign.increment_counter(:leads_count, campaign_id) - end + Campaign.increment_counter(:leads_count, campaign_id) if campaign_id end #---------------------------------------------------------------------------- def decrement_leads_count - if campaign_id - Campaign.decrement_counter(:leads_count, campaign_id) - end + Campaign.decrement_counter(:leads_count, campaign_id) if campaign_id end # Make sure at least one user has been selected if the lead is being shared. diff --git a/app/models/entities/opportunity.rb b/app/models/entities/opportunity.rb index 4a0d24981f..52641df20c 100644 --- a/app/models/entities/opportunity.rb +++ b/app/models/entities/opportunity.rb @@ -175,16 +175,12 @@ def users_for_shared_access #---------------------------------------------------------------------------- def increment_opportunities_count - if campaign_id - Campaign.increment_counter(:opportunities_count, campaign_id) - end + Campaign.increment_counter(:opportunities_count, campaign_id) if campaign_id end #---------------------------------------------------------------------------- def decrement_opportunities_count - if campaign_id - Campaign.decrement_counter(:opportunities_count, campaign_id) - end + Campaign.decrement_counter(:opportunities_count, campaign_id) if campaign_id end ActiveSupport.run_load_hooks(:fat_free_crm_opportunity, self) diff --git a/app/models/setting.rb b/app/models/setting.rb index bf9cbab88e..6113c47bc1 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -56,15 +56,11 @@ def [](name) # Check database if database_and_table_exists? if setting = find_by_name(name.to_s) - unless setting.value.nil? - return cache[name] = setting.value - end + return cache[name] = setting.value unless setting.value.nil? end end # Check YAML settings - if yaml_settings.key?(name) - return cache[name] = yaml_settings[name] - end + return cache[name] = yaml_settings[name] if yaml_settings.key?(name) end # Set setting value diff --git a/db/migrate/20100928030620_remove_uuid.rb b/db/migrate/20100928030620_remove_uuid.rb index e944a04a8f..0dbb9dc5b8 100644 --- a/db/migrate/20100928030620_remove_uuid.rb +++ b/db/migrate/20100928030620_remove_uuid.rb @@ -4,9 +4,7 @@ class RemoveUuid < ActiveRecord::Migration def self.up [:users, :accounts, :campaigns, :leads, :contacts, :opportunities, :tasks].each do |table| remove_column table, :uuid - if self.uuid_configured? - execute("DROP TRIGGER IF EXISTS #{table}_uuid") - end + execute("DROP TRIGGER IF EXISTS #{table}_uuid") if self.uuid_configured? end end diff --git a/lib/fat_free_crm.rb b/lib/fat_free_crm.rb index e75330c455..3a2b3463c4 100644 --- a/lib/fat_free_crm.rb +++ b/lib/fat_free_crm.rb @@ -26,9 +26,7 @@ def application? end # Load Fat Free CRM as a Rails Engine, unless running as a Rails Application -unless defined?(FatFreeCRM::Application) - require 'fat_free_crm/engine' -end +require 'fat_free_crm/engine' unless defined?(FatFreeCRM::Application) require 'fat_free_crm/load_settings' # register load hook for Setting diff --git a/lib/fat_free_crm/mail_processor/base.rb b/lib/fat_free_crm/mail_processor/base.rb index f45d0c474c..63320e9b36 100644 --- a/lib/fat_free_crm/mail_processor/base.rb +++ b/lib/fat_free_crm/mail_processor/base.rb @@ -82,9 +82,7 @@ def connect!(options = {}) def disconnect! if @imap @imap.logout - unless @imap.disconnected? - @imap.disconnect rescue nil - end + @imap.disconnect rescue nil unless @imap.disconnected? end end diff --git a/lib/tasks/ffcrm/update_data.rake b/lib/tasks/ffcrm/update_data.rake index 30afe9f159..7dead054a6 100644 --- a/lib/tasks/ffcrm/update_data.rake +++ b/lib/tasks/ffcrm/update_data.rake @@ -217,9 +217,7 @@ in a console and continue. This is strongly discouraged. You have been warned! tmp = Address.where(scope) tmp.map { |t| t.country = ct[2] } - unless tmp.blank? - addresses_to_update << tmp - end + addresses_to_update << tmp unless tmp.blank? end Address.transaction do