popstar 0.0.3.3 → 0.0.3.5
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.
- data/lib/popstar.rb +1 -0
- data/lib/popstar/migration.rb +27 -0
- data/lib/popstar/rule_group.rb +6 -0
- data/lib/popstar/version.rb +1 -1
- data/lib/tasks/popstar_tasks.rake +6 -4
- metadata +5 -4
data/lib/popstar.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Popstar
|
2
|
+
class Migration
|
3
|
+
@@rules = {}
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def up
|
7
|
+
@@rules.each do |target, rules|
|
8
|
+
rules.each do |rule|
|
9
|
+
if rule[:action] == :create
|
10
|
+
rule[:model].all.each do |model|
|
11
|
+
model.send(target).inc(:popularity, rule[:rate].call(model))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def rules
|
19
|
+
@@rules || {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def rules=(rules)
|
23
|
+
@@rules ||= rules
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/popstar/rule_group.rb
CHANGED
@@ -21,6 +21,12 @@ module Popstar
|
|
21
21
|
|
22
22
|
target = @target
|
23
23
|
|
24
|
+
if Popstar::Migration.rules[target].present?
|
25
|
+
Popstar::Migration.rules[target] << { :action => action, :model => model, :rate => rate }
|
26
|
+
else
|
27
|
+
Popstar::Migration.rules[target] = [{ :action => action, :model => model, :rate => rate }]
|
28
|
+
end
|
29
|
+
|
24
30
|
increase_popularity = proc do |model|
|
25
31
|
model.send(target).inc(:popularity, rate.call(model))
|
26
32
|
end
|
data/lib/popstar/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: popstar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3.
|
4
|
+
version: 0.0.3.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-07-
|
13
|
+
date: 2012-07-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- app/models/popularity_rules.rb
|
103
103
|
- config/initializers/boot.rb
|
104
104
|
- lib/popstar/engine.rb
|
105
|
+
- lib/popstar/migration.rb
|
105
106
|
- lib/popstar/popular.rb
|
106
107
|
- lib/popstar/popularity.rb
|
107
108
|
- lib/popstar/rule_group.rb
|
@@ -125,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
126
|
version: '0'
|
126
127
|
segments:
|
127
128
|
- 0
|
128
|
-
hash: -
|
129
|
+
hash: -4125719730596984683
|
129
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
131
|
none: false
|
131
132
|
requirements:
|
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
version: '0'
|
135
136
|
segments:
|
136
137
|
- 0
|
137
|
-
hash: -
|
138
|
+
hash: -4125719730596984683
|
138
139
|
requirements: []
|
139
140
|
rubyforge_project:
|
140
141
|
rubygems_version: 1.8.24
|