popstar 0.0.3.3 → 0.0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/popstar.rb CHANGED
@@ -2,6 +2,7 @@ require 'popstar/engine'
2
2
  require 'popstar/popular'
3
3
  require 'popstar/popularity'
4
4
  require 'popstar/rule_group'
5
+ require 'popstar/migration'
5
6
 
6
7
  module Popstar
7
8
  end
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Popstar
2
- VERSION = "0.0.3.3"
2
+ VERSION = "0.0.3.5"
3
3
  end
@@ -1,4 +1,6 @@
1
- # desc "Explaining what the task does"
2
- # task :popstar do
3
- # # Task goes here
4
- # end
1
+ namespace :popstar do
2
+ desc "Migrates the database to new popularity rules"
3
+ task :migrate => :environment do
4
+ Popstar::Migration.up
5
+ end
6
+ end
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.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-12 00:00:00.000000000 Z
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: -2780434342361511103
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: -2780434342361511103
138
+ hash: -4125719730596984683
138
139
  requirements: []
139
140
  rubyforge_project:
140
141
  rubygems_version: 1.8.24