active_touch 3.0.3 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +1 -1
- data/lib/active_touch.rb +1 -0
- data/lib/active_touch/define_touch.rb +24 -10
- data/lib/active_touch/touch.rb +41 -0
- data/lib/active_touch/touch_job.rb +2 -17
- data/lib/active_touch/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTI4NzU0Y2UwMTAwM2ExYmE5ZjYwZmJmY2NkNzI5ZGEzNmExYjU3Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzdmMzg2MGY1ZWNjZTViYTg2OWE2ZGZlNTU4OGRiNWE0Yzc2NTA0OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWNkMDQ2YTFlYjE5MDdjODNhNWZjYWYyNDM2MTQ5Njg2MjIxMDQwMGU5NmNj
|
10
|
+
ZjMyYTJjN2YyMTI4MjkzNzI2NTRlYzUzMmU0MWNkMzI5NmY0NmQyZjI0Mzlm
|
11
|
+
YzY1NmJmYzQzYWI3MTE4NDRiZjk0MjkwYTA0N2NkMGRlNThkZjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGNkMTVlM2U3ZDViYmIyZjEzMmMzYjljMzUxOTdiMTRlZDI2YWUwMzcyNjY3
|
14
|
+
YzgzODA2YzczMDA1MzkzMmZlNzFmYTdjNmNkYzIyOGQ0NDg3MzBjMjRhZWMz
|
15
|
+
ZjVjNTJiYTFiNWQzZDcwZWRlM2FkMGM2ZTA3ODdlZTdiMzhjN2Q=
|
data/README.md
CHANGED
data/lib/active_touch.rb
CHANGED
@@ -11,20 +11,25 @@ module ActiveTouch
|
|
11
11
|
@klass = klass
|
12
12
|
@association = association
|
13
13
|
@options = default_options.merge(options)
|
14
|
-
@
|
14
|
+
@update_touch_method = "touch_#{SecureRandom.uuid}"
|
15
|
+
@destroy_touch_method = "touch_#{SecureRandom.uuid}"
|
15
16
|
end
|
16
17
|
|
17
18
|
def define
|
18
|
-
|
19
|
-
add_active_record_callback
|
19
|
+
define_update_touch_method
|
20
|
+
add_active_record_callback(@update_touch_method)
|
21
|
+
|
22
|
+
define_destroy_touch_method
|
23
|
+
add_active_record_callback(@destroy_touch_method)
|
24
|
+
|
20
25
|
add_to_network
|
21
26
|
end
|
22
27
|
|
23
|
-
def
|
28
|
+
def define_update_touch_method
|
24
29
|
association = @association
|
25
30
|
options = @options
|
26
31
|
|
27
|
-
@klass.send :define_method, @
|
32
|
+
@klass.send :define_method, @update_touch_method do |*args|
|
28
33
|
changed_attributes = self.previous_changes.keys.map(&:to_sym)
|
29
34
|
watched_changes = (options[:watch] & changed_attributes)
|
30
35
|
|
@@ -35,19 +40,28 @@ module ActiveTouch
|
|
35
40
|
if options[:async]
|
36
41
|
TouchJob
|
37
42
|
.set(queue: ActiveTouch.configuration.queue)
|
38
|
-
.perform_later(self, association.to_s, options[:after_touch].to_s
|
43
|
+
.perform_later(self, association.to_s, options[:after_touch].to_s)
|
39
44
|
|
40
45
|
else
|
41
|
-
TouchJob.perform_now(self, association.to_s, options[:after_touch].to_s
|
46
|
+
TouchJob.perform_now(self, association.to_s, options[:after_touch].to_s)
|
42
47
|
end
|
43
48
|
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
53
|
+
def define_destroy_touch_method
|
54
|
+
association = @association
|
55
|
+
options = @options
|
56
|
+
|
57
|
+
@klass.send :define_method, @destroy_touch_method do |*args|
|
58
|
+
Rails.logger.debug "Touch: #{self.class}(#{self.id}) => #{association} due to destroy"
|
59
|
+
TouchJob.perform_now(self, association.to_s, options[:after_touch].to_s, true)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_active_record_callback(method)
|
64
|
+
@klass.send(:after_commit) { send(method) }
|
51
65
|
end
|
52
66
|
|
53
67
|
def add_to_network
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ActiveTouch
|
2
|
+
class Touch
|
3
|
+
|
4
|
+
attr_accessor :record, :association, :after_touch, :is_destroy
|
5
|
+
|
6
|
+
def initialize(record, association, after_touch, is_destroy = false)
|
7
|
+
@record = record
|
8
|
+
@association = association
|
9
|
+
@after_touch = after_touch
|
10
|
+
@is_destroy = is_destroy
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
if associated.is_a? ActiveRecord::Base
|
15
|
+
unless ActiveTouch.configuration.timestamp_attribute.nil?
|
16
|
+
associated.update_columns(ActiveTouch.configuration.timestamp_attribute => record.updated_at)
|
17
|
+
end
|
18
|
+
|
19
|
+
associated.send(after_touch) unless after_touch.blank?
|
20
|
+
|
21
|
+
elsif !associated.nil? && !associated.empty?
|
22
|
+
unless ActiveTouch.configuration.timestamp_attribute.nil?
|
23
|
+
associated.update_all(ActiveTouch.configuration.timestamp_attribute => record.updated_at)
|
24
|
+
end
|
25
|
+
|
26
|
+
associated.each { |associate| associate.send(after_touch) } unless after_touch.blank?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def associated
|
31
|
+
@associated ||= begin
|
32
|
+
if association == 'self'
|
33
|
+
is_destroy ? nil : record
|
34
|
+
else
|
35
|
+
record.send(association)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -1,23 +1,8 @@
|
|
1
1
|
module ActiveTouch
|
2
2
|
class TouchJob < ActiveJob::Base
|
3
3
|
|
4
|
-
def perform(record, association, after_touch,
|
5
|
-
|
6
|
-
|
7
|
-
if associated.is_a? ActiveRecord::Base
|
8
|
-
unless ActiveTouch.configuration.timestamp_attribute.nil?
|
9
|
-
associated.update_columns(ActiveTouch.configuration.timestamp_attribute => record.updated_at)
|
10
|
-
end
|
11
|
-
|
12
|
-
associated.send(after_touch) unless after_touch.blank?
|
13
|
-
|
14
|
-
elsif !associated.nil? && !associated.empty?
|
15
|
-
unless ActiveTouch.configuration.timestamp_attribute.nil?
|
16
|
-
associated.update_all(ActiveTouch.configuration.timestamp_attribute => record.updated_at)
|
17
|
-
end
|
18
|
-
|
19
|
-
associated.each { |associate| associate.send(after_touch) } unless after_touch.blank?
|
20
|
-
end
|
4
|
+
def perform(record, association, after_touch, is_destroy = false)
|
5
|
+
Touch.new(record, association, after_touch, is_destroy).run
|
21
6
|
end
|
22
7
|
|
23
8
|
end
|
data/lib/active_touch/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_touch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Pheasey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/active_touch/configuration.rb
|
75
75
|
- lib/active_touch/define_touch.rb
|
76
76
|
- lib/active_touch/network.rb
|
77
|
+
- lib/active_touch/touch.rb
|
77
78
|
- lib/active_touch/touch_job.rb
|
78
79
|
- lib/active_touch/version.rb
|
79
80
|
- lib/generators/active_touch/initializer_generator.rb
|