popstar4 1.0.1
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 +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +56 -0
- data/Rakefile +23 -0
- data/app/models/popularity_rules.rb +6 -0
- data/config/initializers/boot.rb +1 -0
- data/lib/popstar.rb +8 -0
- data/lib/popstar4/engine.rb +5 -0
- data/lib/popstar4/migration.rb +27 -0
- data/lib/popstar4/popular.rb +7 -0
- data/lib/popstar4/popularity.rb +11 -0
- data/lib/popstar4/rule_group.rb +42 -0
- data/lib/popstar4/version.rb +3 -0
- data/lib/tasks/popstar_tasks.rake +6 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MmU5NzgwYjYxZDA5MDlhZTUxNjk0N2M2ZjI1YjNiNzA4NWZhYTE0MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWNlMmRkOTk3YTEyYmQ3ODE0NzY5MDFjMzk3MjJiNTNmMDdkNzQ2OA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OWVmOWM0MWQ1YjI0MzQzMDZlZmNiNTc1OTlkNzgxMWVkYzc2Mjk2NWZlNzJl
|
10
|
+
ZDU1ZTcwOGM3NWQwYjNmZDYzYjBlZmEyNTdiYzkxNzY0ZmUyZjQ5NDI3ZmNi
|
11
|
+
ZjY3YzQyZDYxMjVkNDg1ZDJhZmVlYzA3MTI0NDA1ZmQ4NGI2MWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
N2Q2MjQxYjAzMDY3YWFkMjIzZjUxYmI4ODdkOGQwNDczMWM0YzZlNjg2OTM2
|
14
|
+
N2FlOWYzYmJiN2E4YTllZDVhYWQxY2JiNjM5Yzk0MjNiZGEzNTY0NzZjOWU4
|
15
|
+
OTdlNTRjMzdjOGNmZTlmMDVhYmY5OGEzZjdkYWM5ZWFjZmE2ZDE=
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Popstar4
|
2
|
+
Evolution of [Popstar repo][lps] for Rails4
|
3
|
+
|
4
|
+
____________________________________
|
5
|
+
|
6
|
+
|
7
|
+
Popularity system for your Rails models.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Put this in your gemfile:
|
12
|
+
|
13
|
+
`gem 'popstar4'`
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Define your badge rules in a PopularityRules class
|
18
|
+
|
19
|
+
```
|
20
|
+
class PopularityRules
|
21
|
+
include Popstar4::Popularity
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
popularity_for :voteable do
|
25
|
+
on :create, Vote, :rate => proc { |vote| vote.rate*2 }
|
26
|
+
on :update, Vote, :rate => proc { |vote| (vote.rate - vote.rate_was)*2 }
|
27
|
+
end
|
28
|
+
|
29
|
+
popularity_for :question do
|
30
|
+
on :create, Answer, :rate => 2
|
31
|
+
end
|
32
|
+
|
33
|
+
popularity_for :viewable do
|
34
|
+
on :create, ViewsCount
|
35
|
+
end
|
36
|
+
|
37
|
+
popularity_for :widget do
|
38
|
+
on :create, Comment
|
39
|
+
on :create, Question, :rate => 2
|
40
|
+
on :create, Answer, :rate => 3
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
## Supported ORMS
|
47
|
+
|
48
|
+
- Mongoid
|
49
|
+
|
50
|
+
## TODO
|
51
|
+
|
52
|
+
- Add support for ActiveRecord
|
53
|
+
- Add rake tasks to migrate popular models after defining rules
|
54
|
+
|
55
|
+
|
56
|
+
[lps]: <https://github.com/responsa/popstar>
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Popstar4'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.md')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1 @@
|
|
1
|
+
PopularityRules.instance
|
data/lib/popstar.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Popstar4
|
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).try(: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
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Popstar4
|
2
|
+
class RuleGroup
|
3
|
+
def initialize(target, &block)
|
4
|
+
@target = target
|
5
|
+
instance_eval(&block) if block_given?
|
6
|
+
end
|
7
|
+
|
8
|
+
def on(action, model, *args)
|
9
|
+
options = args.extract_options!
|
10
|
+
options.reverse_merge!(
|
11
|
+
:rate => 1
|
12
|
+
)
|
13
|
+
|
14
|
+
rate = begin
|
15
|
+
if options[:rate].respond_to?(:call)
|
16
|
+
options[:rate]
|
17
|
+
else
|
18
|
+
proc { options[:rate] }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
target = @target
|
23
|
+
|
24
|
+
if Popstar4::Migration.rules[target].present?
|
25
|
+
Popstar4::Migration.rules[target] << { :action => action, :model => model, :rate => rate }
|
26
|
+
else
|
27
|
+
Popstar4::Migration.rules[target] = [{ :action => action, :model => model, :rate => rate }]
|
28
|
+
end
|
29
|
+
|
30
|
+
increase_popularity = proc do |model|
|
31
|
+
model.send(target).inc(:popularity, rate.call(model))
|
32
|
+
end
|
33
|
+
|
34
|
+
decrease_popularity = proc do |model|
|
35
|
+
model.try(:send, target).try(:inc, :popularity, -rate.call(model))
|
36
|
+
end
|
37
|
+
|
38
|
+
model.send("after_#{action}", increase_popularity)
|
39
|
+
model.send("after_destroy", decrease_popularity) if action == :create
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: popstar4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Zanardo
|
8
|
+
- Matteo Depalo
|
9
|
+
- Eugenio Depalo
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2015-11-16 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '4.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '4.0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: mongoid
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 3.0.0
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 3.0.0
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rspec-rails
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: mongoid-rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
description: Popstar lets you add rules to determine your rails4 models popularity.
|
72
|
+
email:
|
73
|
+
- info@alexzanardo.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- MIT-LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- app/models/popularity_rules.rb
|
82
|
+
- config/initializers/boot.rb
|
83
|
+
- lib/popstar.rb
|
84
|
+
- lib/popstar4/engine.rb
|
85
|
+
- lib/popstar4/migration.rb
|
86
|
+
- lib/popstar4/popular.rb
|
87
|
+
- lib/popstar4/popularity.rb
|
88
|
+
- lib/popstar4/rule_group.rb
|
89
|
+
- lib/popstar4/version.rb
|
90
|
+
- lib/tasks/popstar_tasks.rake
|
91
|
+
homepage: https://github.com/responsa/popstar4
|
92
|
+
licenses: []
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.0
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Popularity system for your Rails4 models.
|
114
|
+
test_files: []
|