From f727aecde9948998271629cbdc964aa9523109ed Mon Sep 17 00:00:00 2001 From: Kevin Pheasey Date: Fri, 14 Oct 2016 20:42:13 -0400 Subject: [PATCH] Refactor DefineTouch to remove redundant hash declarations. --- lib/active_touch.rb | 11 +++++------ lib/active_touch/define_touch.rb | 27 +++++++++------------------ lib/active_touch/version.rb | 2 +- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/lib/active_touch.rb b/lib/active_touch.rb index 4b573e8..64c9277 100644 --- a/lib/active_touch.rb +++ b/lib/active_touch.rb @@ -1,13 +1,12 @@ -require 'active_touch/version' +require 'active_support/concern' +require 'active_job/base' +require 'active_record/base' + require 'active_touch/configuration' require 'active_touch/define_touch' require 'active_touch/network' -require 'active_touch/touch' require 'active_touch/touch_job' - -require 'active_support/concern' -require 'active_job/base' -require 'active_record/base' +require 'active_touch/version' module ActiveTouch extend ActiveSupport::Concern diff --git a/lib/active_touch/define_touch.rb b/lib/active_touch/define_touch.rb index eb0f71c..f999bb5 100644 --- a/lib/active_touch/define_touch.rb +++ b/lib/active_touch/define_touch.rb @@ -41,10 +41,9 @@ def define_before_commit_method changed_attributes = self.previous_changes.keys.map(&:to_sym) watched_changes = (options[:watch] & changed_attributes) - # watched values changed and conditional procs evaluate to true if watched_changes.any? && options[:if].call(self) && !options[:unless].call(self) - Rails.logger.debug "Touch Before Commit: #{self.class}(#{self.id}) => #{association} due to changes in #{watched_changes}" TouchJob.perform_now(self, association.to_s, touch_updates: options[:touch_updates]) + Rails.logger.debug "Touch Before Commit: #{self.class}(#{self.id}) => #{association} due to changes in #{watched_changes}" end end end @@ -57,27 +56,19 @@ def define_after_commit_method changed_attributes = self.previous_changes.keys.map(&:to_sym) watched_changes = (options[:watch] & changed_attributes) - # watched values changed and conditional procs evaluate to true if watched_changes.any? && options[:if].call(self) && !options[:unless].call(self) Rails.logger.debug "Touch After Commit: #{self.class}(#{self.id}) => #{association} due to changes in #{watched_changes}" + options = { + after_touch: options[:after_touch].to_s, + is_destroy: false, + is_touched: options[:touch_in_transaction], + touch_updates: options[:touch_updates] + } if options[:async] - TouchJob - .set(queue: ActiveTouch.configuration.queue) - .perform_later(self, association.to_s, { - after_touch: options[:after_touch].to_s, - is_destroy: false, - is_touched: options[:touch_in_transaction], - touch_updates: options[:touch_updates] - }) - + TouchJob.set(queue: ActiveTouch.configuration.queue).perform_later(self, association.to_s, options) else - TouchJob.perform_now(self, association.to_s, { - after_touch: options[:after_touch].to_s, - is_destroy: false, - is_touched: options[:touch_in_transaction], - touch_updates: options[:touch_updates] - }) + TouchJob.perform_now(self, association.to_s, options) end end diff --git a/lib/active_touch/version.rb b/lib/active_touch/version.rb index 68df2ca..de7e839 100644 --- a/lib/active_touch/version.rb +++ b/lib/active_touch/version.rb @@ -1,3 +1,3 @@ module ActiveTouch - VERSION = '4.2.1' + VERSION = '5.0.0' end