trendable 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +8 -1
- data/lib/trendable/version.rb +1 -1
- data/lib/workers/fade_out_trend_power_worker.rb +2 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f3496ff5b5f317e0ac19af1fc510daebab600b9
|
4
|
+
data.tar.gz: 235bff5831a602bf1417f74b8157a8ac609bb8b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12e94fbaa8060d5fb3cae3464a8837318ba8e2e8f9b85e0bf9e1baae77dd287c773df29dbef8afebff42cd7cebf37fb8750e8ea9ce6395f1c5117785f7317072
|
7
|
+
data.tar.gz: bfea558e138bc6ce0b0d61cc8636c70f140999902267bed6d9209b48fef7c736b9a482422057ffa3fc5b4ed247c43afd271eb1542ec2a17b88fa84a961745c43
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,7 @@ Add management for ordering your models by a trending popularity value.
|
|
10
10
|
|
11
11
|
# Add a migration:
|
12
12
|
$ rails g trendable:migration widget
|
13
|
+
$ bundle exec rake db:migrate
|
13
14
|
|
14
15
|
# Update your model to include the concern
|
15
16
|
# app/models/widget.rb
|
@@ -24,4 +25,10 @@ Add management for ordering your models by a trending popularity value.
|
|
24
25
|
|
25
26
|
20.times{ Widget.first.fade_trending_power }
|
26
27
|
|
27
|
-
Widget.order_by_trending
|
28
|
+
Widget.order_by_trending
|
29
|
+
|
30
|
+
You can use the `FadeOutTrendPowerWorker` to lower the trending power over time.
|
31
|
+
|
32
|
+
For example, you might run it once an hour to fade out the power of the widget. In this way, the more recent the boost, the more trending power.
|
33
|
+
|
34
|
+
Note that the `FadeOutTrendingPowerWorker` does not hit any callbacks. It's an `update_all` on the table (for performance).
|
data/lib/trendable/version.rb
CHANGED
@@ -6,10 +6,8 @@ class FadeOutTrendPowerWorker
|
|
6
6
|
|
7
7
|
ActiveRecord::Base.descendants.each do |klass|
|
8
8
|
if klass.respond_to?( "has_trendable_concern?".to_sym )
|
9
|
-
|
10
|
-
|
11
|
-
inst.fade_out_trending_power!( multiplier )
|
12
|
-
end
|
9
|
+
|
10
|
+
klass.update_all( "trending_power = trending_power * #{multiplier}")
|
13
11
|
else
|
14
12
|
puts "#{klass.to_s} does not have trendable concern"
|
15
13
|
end
|