From ecb78233d933de5ede3d124382debd85b9908dca Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 7 Jul 2017 15:31:18 +1000 Subject: [PATCH] Use guard clauses where possible --- app/controllers/spree/credit_cards_controller.rb | 5 ++--- app/controllers/spree/users_controller_decorator.rb | 6 +++--- app/models/spree/payment_decorator.rb | 10 +++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/controllers/spree/credit_cards_controller.rb b/app/controllers/spree/credit_cards_controller.rb index 2fb4d51a05..ee9373e1ce 100644 --- a/app/controllers/spree/credit_cards_controller.rb +++ b/app/controllers/spree/credit_cards_controller.rb @@ -30,9 +30,8 @@ module Spree # Currently can only destroy the whole customer object def destroy_at_stripe - if stripe_customer = Stripe::Customer.retrieve( @credit_card.gateway_customer_profile_id ) - stripe_customer.delete - end + stripe_customer = Stripe::Customer.retrieve(@credit_card.gateway_customer_profile_id) + stripe_customer.delete if stripe_customer end private diff --git a/app/controllers/spree/users_controller_decorator.rb b/app/controllers/spree/users_controller_decorator.rb index 1657f17727..bfdd83f839 100644 --- a/app/controllers/spree/users_controller_decorator.rb +++ b/app/controllers/spree/users_controller_decorator.rb @@ -9,9 +9,9 @@ Spree::UsersController.class_eval do def show @orders = @user.orders.where(state: 'complete').order('completed_at desc') - if Spree::Config.accounts_distributor_id - @orders = @orders.where('distributor_id != ?', Spree::Config.accounts_distributor_id) - end + return unless Spree::Config.accounts_distributor_id + + @orders = @orders.where('distributor_id != ?', Spree::Config.accounts_distributor_id) end private diff --git a/app/models/spree/payment_decorator.rb b/app/models/spree/payment_decorator.rb index a13f71e041..568d82371a 100644 --- a/app/models/spree/payment_decorator.rb +++ b/app/models/spree/payment_decorator.rb @@ -78,11 +78,11 @@ module Spree # Import from future Spree def build_source return if source_attributes.nil? - if payment_method && payment_method.payment_source_class - self.source = payment_method.payment_source_class.new(source_attributes) - source.payment_method_id = payment_method.id - source.user_id = order.user_id if order - end + return unless payment_method.andand.payment_source_class + + self.source = payment_method.payment_source_class.new(source_attributes) + source.payment_method_id = payment_method.id + source.user_id = order.user_id if order end private