delayed_touch_associations 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/lib/delayed_touch_associations.rb +10 -5
- data/lib/delayed_touch_associations/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
delayed_touch_associations
|
2
2
|
==========================
|
3
3
|
|
4
|
-
Delayed Job integration for the touch option of ActiveRecord belongs_to association
|
4
|
+
Delayed Job integration for the touch option of ActiveRecord belongs_to association.
|
5
5
|
|
6
|
+
This gem delays all the touch callbacks defined by the touch option of all the belongs_to associations in the models it's included.
|
7
|
+
It calls the delay method defined in delayed_job when the callback is triggered, minimizing the time it takes to save the record.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -5,12 +5,17 @@ module DelayedTouchAssociations
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
self.reflect_on_all_associations.select {|a| a.options[:touch] }.each do |association|
|
8
|
+
touch = association.options[:touch]
|
8
9
|
method_name = "belongs_to_touch_after_save_or_destroy_for_#{association.name}"
|
9
|
-
define_method(method_name) do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
define_method(method_name) do
|
11
|
+
record = send(association.name)
|
12
|
+
|
13
|
+
unless record.nil?
|
14
|
+
if touch == true
|
15
|
+
record.delay.touch
|
16
|
+
else
|
17
|
+
record.delay.touch(touch)
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|