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 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 |delayed = false|
10
- if delayed
11
- super()
12
- else
13
- self.delay.send(method_name, true)
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
@@ -1,3 +1,3 @@
1
1
  module DelayedTouchAssociations
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_touch_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: