Skip to content

Commit

Permalink
Refactor DefineTouch to remove redundant hash declarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Pheasey committed Oct 15, 2016
1 parent 61432e6 commit f727aec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
11 changes: 5 additions & 6 deletions lib/active_touch.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 9 additions & 18 deletions lib/active_touch/define_touch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/active_touch/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveTouch
VERSION = '4.2.1'
VERSION = '5.0.0'
end

0 comments on commit f727aec

Please sign in to comment.