active_touch 4.2.1 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_touch.rb +5 -6
- data/lib/active_touch/define_touch.rb +9 -18
- data/lib/active_touch/touch_job.rb +34 -1
- data/lib/active_touch/version.rb +1 -1
- metadata +1 -2
- data/lib/active_touch/touch.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6b70d780678e122e010326d0a35f40b196331d8
|
4
|
+
data.tar.gz: f2e40371296d3839fc36503a640fdb4b7b27c969
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5d6eb1d3eecf20ecd2d2a6ae03f2b5c44aeac06aaf304806e27df3ae6f1b438af0ecf2fb05eba58ff6a9fb9ba696f601e68245752d5b72bc43918cec1ba3c9e
|
7
|
+
data.tar.gz: 25526ebd8776633a2186069688da1e4aa79401c43bc0bce65d4a834d22af3b4cb7972c4792fff6525831e83a7a755a89ae03632bd2a4cfc40920a22d81b64f21
|
data/lib/active_touch.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'active_job/base'
|
3
|
+
require 'active_record/base'
|
4
|
+
|
2
5
|
require 'active_touch/configuration'
|
3
6
|
require 'active_touch/define_touch'
|
4
7
|
require 'active_touch/network'
|
5
|
-
require 'active_touch/touch'
|
6
8
|
require 'active_touch/touch_job'
|
7
|
-
|
8
|
-
require 'active_support/concern'
|
9
|
-
require 'active_job/base'
|
10
|
-
require 'active_record/base'
|
9
|
+
require 'active_touch/version'
|
11
10
|
|
12
11
|
module ActiveTouch
|
13
12
|
extend ActiveSupport::Concern
|
@@ -41,10 +41,9 @@ module ActiveTouch
|
|
41
41
|
changed_attributes = self.previous_changes.keys.map(&:to_sym)
|
42
42
|
watched_changes = (options[:watch] & changed_attributes)
|
43
43
|
|
44
|
-
# watched values changed and conditional procs evaluate to true
|
45
44
|
if watched_changes.any? && options[:if].call(self) && !options[:unless].call(self)
|
46
|
-
Rails.logger.debug "Touch Before Commit: #{self.class}(#{self.id}) => #{association} due to changes in #{watched_changes}"
|
47
45
|
TouchJob.perform_now(self, association.to_s, touch_updates: options[:touch_updates])
|
46
|
+
Rails.logger.debug "Touch Before Commit: #{self.class}(#{self.id}) => #{association} due to changes in #{watched_changes}"
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
@@ -57,27 +56,19 @@ module ActiveTouch
|
|
57
56
|
changed_attributes = self.previous_changes.keys.map(&:to_sym)
|
58
57
|
watched_changes = (options[:watch] & changed_attributes)
|
59
58
|
|
60
|
-
# watched values changed and conditional procs evaluate to true
|
61
59
|
if watched_changes.any? && options[:if].call(self) && !options[:unless].call(self)
|
62
60
|
Rails.logger.debug "Touch After Commit: #{self.class}(#{self.id}) => #{association} due to changes in #{watched_changes}"
|
61
|
+
options = {
|
62
|
+
after_touch: options[:after_touch].to_s,
|
63
|
+
is_destroy: false,
|
64
|
+
is_touched: options[:touch_in_transaction],
|
65
|
+
touch_updates: options[:touch_updates]
|
66
|
+
}
|
63
67
|
|
64
68
|
if options[:async]
|
65
|
-
TouchJob
|
66
|
-
.set(queue: ActiveTouch.configuration.queue)
|
67
|
-
.perform_later(self, association.to_s, {
|
68
|
-
after_touch: options[:after_touch].to_s,
|
69
|
-
is_destroy: false,
|
70
|
-
is_touched: options[:touch_in_transaction],
|
71
|
-
touch_updates: options[:touch_updates]
|
72
|
-
})
|
73
|
-
|
69
|
+
TouchJob.set(queue: ActiveTouch.configuration.queue).perform_later(self, association.to_s, options)
|
74
70
|
else
|
75
|
-
TouchJob.perform_now(self, association.to_s,
|
76
|
-
after_touch: options[:after_touch].to_s,
|
77
|
-
is_destroy: false,
|
78
|
-
is_touched: options[:touch_in_transaction],
|
79
|
-
touch_updates: options[:touch_updates]
|
80
|
-
})
|
71
|
+
TouchJob.perform_now(self, association.to_s, options)
|
81
72
|
end
|
82
73
|
|
83
74
|
end
|
@@ -1,9 +1,42 @@
|
|
1
1
|
module ActiveTouch
|
2
2
|
class TouchJob < ActiveJob::Base
|
3
3
|
|
4
|
+
attr_accessor :record, :association, :after_touch, :is_destroy, :is_touched, :touch_updates
|
5
|
+
|
4
6
|
def perform(record, association, options = {})
|
5
|
-
|
7
|
+
@record = record
|
8
|
+
@association = association
|
9
|
+
@after_touch = options[:after_touch]
|
10
|
+
@is_destroy = options[:is_destroy]
|
11
|
+
@is_touched = options[:is_touched]
|
12
|
+
@touch_updates = (options[:touch_updates] || {})
|
13
|
+
|
14
|
+
run
|
6
15
|
end
|
7
16
|
|
17
|
+
def run
|
18
|
+
if !ActiveTouch.configuration.timestamp_attribute.nil?
|
19
|
+
touch_updates[ActiveTouch.configuration.timestamp_attribute] = record.updated_at
|
20
|
+
end
|
21
|
+
|
22
|
+
if associated.is_a? ActiveRecord::Base
|
23
|
+
associated.update_columns(touch_updates) if !touch_updates.empty? && !is_touched
|
24
|
+
associated.send(after_touch) unless after_touch.blank?
|
25
|
+
|
26
|
+
elsif !associated.nil?
|
27
|
+
associated.update_all(touch_updates) if !touch_updates.empty? && !is_touched
|
28
|
+
associated.each { |associate| associate.send(after_touch) } unless after_touch.blank?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def associated
|
33
|
+
@associated ||= begin
|
34
|
+
if association == 'self'
|
35
|
+
is_destroy || record.destroyed? ? nil : record
|
36
|
+
else
|
37
|
+
record.send(association)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
8
41
|
end
|
9
42
|
end
|
data/lib/active_touch/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_touch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Pheasey
|
@@ -80,7 +80,6 @@ files:
|
|
80
80
|
- lib/active_touch/configuration.rb
|
81
81
|
- lib/active_touch/define_touch.rb
|
82
82
|
- lib/active_touch/network.rb
|
83
|
-
- lib/active_touch/touch.rb
|
84
83
|
- lib/active_touch/touch_job.rb
|
85
84
|
- lib/active_touch/version.rb
|
86
85
|
- lib/generators/active_touch/initializer_generator.rb
|
data/lib/active_touch/touch.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module ActiveTouch
|
2
|
-
class Touch
|
3
|
-
|
4
|
-
attr_accessor :record, :association, :after_touch, :is_destroy, :is_touched, :touch_updates
|
5
|
-
|
6
|
-
def initialize(record, association, options = {})
|
7
|
-
@record = record
|
8
|
-
@association = association
|
9
|
-
@after_touch = options[:after_touch]
|
10
|
-
@is_destroy = options[:is_destroy]
|
11
|
-
@is_touched = options[:is_touched]
|
12
|
-
@touch_updates = (options[:touch_updates] || {})
|
13
|
-
end
|
14
|
-
|
15
|
-
def run
|
16
|
-
touch_updates[ActiveTouch.configuration.timestamp_attribute] = record.updated_at
|
17
|
-
|
18
|
-
if associated.is_a? ActiveRecord::Base
|
19
|
-
associated.update_columns(touch_updates) if !ActiveTouch.configuration.timestamp_attribute.nil? && !is_touched
|
20
|
-
associated.send(after_touch) unless after_touch.blank?
|
21
|
-
|
22
|
-
elsif !associated.nil?
|
23
|
-
associated.update_all(touch_updates) if !ActiveTouch.configuration.timestamp_attribute.nil? && !is_touched
|
24
|
-
associated.each { |associate| associate.send(after_touch) } unless after_touch.blank?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def associated
|
29
|
-
@associated ||= begin
|
30
|
-
if association == 'self'
|
31
|
-
is_destroy || record.destroyed? ? nil : record
|
32
|
-
else
|
33
|
-
record.send(association)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|