merit 0.5.0 → 0.6.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.
- data/Gemfile.lock +1 -1
- data/README.md +1 -2
- data/UPGRADING.md +15 -0
- data/app/models/merit_action.rb +1 -1
- data/lib/generators/merit/install_generator.rb +3 -3
- data/lib/generators/merit/templates/merit_badge_rules.rb +20 -20
- data/lib/generators/merit/templates/merit_point_rules.rb +15 -15
- data/lib/generators/merit/templates/merit_rank_rules.rb +16 -16
- data/lib/merit/controller_extensions.rb +2 -2
- data/lib/merit/rules_badge.rb +1 -1
- data/lib/merit/rules_points.rb +1 -1
- data/lib/merit/rules_rank.rb +1 -1
- data/merit.gemspec +1 -1
- data/test/dummy/app/models/merit/badge_rules.rb +41 -0
- data/test/dummy/app/models/merit/point_rules.rb +18 -0
- data/test/dummy/app/models/{merit_rank_rules.rb → merit/rank_rules.rb} +8 -8
- data/test/integration/navigation_test.rb +3 -3
- metadata +14 -14
- data/test/dummy/app/models/merit_badge_rules.rb +0 -41
- data/test/dummy/app/models/merit_point_rules.rb +0 -18
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -96,7 +96,7 @@ Define rules on <tt>app/models/merit_rank_rules.rb</tt>:
|
|
96
96
|
Check for rules on a rake task executed in background like:
|
97
97
|
|
98
98
|
task :cron => :environment do
|
99
|
-
|
99
|
+
Merit::RankRules.new.check_rank_rules
|
100
100
|
end
|
101
101
|
|
102
102
|
|
@@ -115,7 +115,6 @@ Check for rules on a rake task executed in background like:
|
|
115
115
|
# To-do list
|
116
116
|
|
117
117
|
* Abstract User (rule.rb#51 for instance) into a Merit option.
|
118
|
-
* What happens if 'class MeritPointRules; include Merit::PointRules' is changed by 'module Merit::PointRules'?
|
119
118
|
* Should namespace app/models into Merit module.
|
120
119
|
* rescue ActiveRecord::... should depend on ORM used (MongoMapper?)
|
121
120
|
* Why 1.8.7 tests are not passing?
|
data/UPGRADING.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# Upgrading
|
2
2
|
|
3
|
+
## to 0.6.0
|
4
|
+
|
5
|
+
<tt>MeritBadgeRules</tt>, <tt>MeritPointRules</tt> and <tt>MeritRankRules</tt>
|
6
|
+
are now namespaced into Merit module. Move and change:
|
7
|
+
|
8
|
+
<pre>
|
9
|
+
app/models/merit_{badge|point|rank}_rules.rb -> app/models/merit/{badge|point|rank}_rules.rb
|
10
|
+
</pre>
|
11
|
+
<pre>
|
12
|
+
-class Merit{Badge|Point|Rank}Rules
|
13
|
+
- include Merit::{Badge|Point|Rank}Rules
|
14
|
+
+module Merit
|
15
|
+
+ class {Badge|Point|Rank}Rules
|
16
|
+
</pre>
|
17
|
+
|
3
18
|
## to 0.5.0
|
4
19
|
|
5
20
|
Add <tt>log:string</tt> column to <tt>merit_actions</tt> table.
|
data/app/models/merit_action.rb
CHANGED
@@ -14,7 +14,7 @@ class MeritAction
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Check Point rules
|
17
|
-
actions_to_point =
|
17
|
+
actions_to_point = Merit::PointRules.new.actions_to_point
|
18
18
|
if actions_to_point[action_name].present?
|
19
19
|
point_rule = actions_to_point[action_name]
|
20
20
|
point_rule[:to].each do |to|
|
@@ -5,9 +5,9 @@ module Merit
|
|
5
5
|
desc "Copy config and rules files"
|
6
6
|
def copy_migrations_and_model
|
7
7
|
template 'merit.rb', 'config/initializers/merit.rb'
|
8
|
-
template 'merit_badge_rules.rb', 'app/models/
|
9
|
-
template 'merit_point_rules.rb', 'app/models/
|
10
|
-
template 'merit_rank_rules.rb', 'app/models/
|
8
|
+
template 'merit_badge_rules.rb', 'app/models/merit/badge_rules.rb'
|
9
|
+
template 'merit_point_rules.rb', 'app/models/merit/point_rules.rb'
|
10
|
+
template 'merit_rank_rules.rb', 'app/models/merit/rank_rules.rb'
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -14,27 +14,27 @@
|
|
14
14
|
# badge is granted, then it's removed. It's false by default (badges are kept
|
15
15
|
# forever).
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
module Merit
|
18
|
+
class BadgeRules
|
19
|
+
def initialize
|
20
|
+
# If it creates user, grant badge
|
21
|
+
# Should be "current_user" after registration for badge to be granted.
|
22
|
+
# grant_on 'users#create', :badge => 'just-registered', :to => :itself
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
# If it has 10 comments, grant commenter-10 badge
|
25
|
+
# grant_on 'comments#create', :badge => 'commenter', :level => 10 do |comment|
|
26
|
+
# comment.user.comments.count == 10
|
27
|
+
# end
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
# If it has 5 votes, grant relevant-commenter badge
|
30
|
+
# grant_on 'comments#vote', :badge => 'relevant-commenter', :to => :user do |comment|
|
31
|
+
# comment.votes.count == 5
|
32
|
+
# end
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# Changes his name by one wider than 4 chars (arbitrary ruby code case)
|
36
|
-
# grant_on 'registrations#update', :badge => 'autobiographer', :temporary => true, :model_name => 'User' do |user|
|
37
|
-
# user.name.length > 4
|
38
|
-
# end
|
34
|
+
# Changes his name by one wider than 4 chars (arbitrary ruby code case)
|
35
|
+
# grant_on 'registrations#update', :badge => 'autobiographer', :temporary => true, :model_name => 'User' do |user|
|
36
|
+
# user.name.length > 4
|
37
|
+
# end
|
38
|
+
end
|
39
39
|
end
|
40
|
-
end
|
40
|
+
end
|
@@ -3,19 +3,19 @@
|
|
3
3
|
# actions-triggered, either to the action user or to the method (or array of
|
4
4
|
# methods) defined in the +:to+ option.
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
module Merit
|
7
|
+
class PointRules
|
8
|
+
def initialize
|
9
|
+
# score 10, :on => [
|
10
|
+
# 'users#update'
|
11
|
+
# ]
|
12
|
+
#
|
13
|
+
# score 15, :on => 'reviews#create', :to => [:reviewer, :reviewed]
|
14
|
+
#
|
15
|
+
# score 20, :on => [
|
16
|
+
# 'comments#create',
|
17
|
+
# 'photos#create'
|
18
|
+
# ]
|
19
|
+
end
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
@@ -8,20 +8,20 @@
|
|
8
8
|
# * :+level_name+ attribute name (default is empty and results in 'level'
|
9
9
|
# attribute, if set it's appended like 'level_#{level_name}')
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
module Merit
|
12
|
+
class RankRules
|
13
|
+
def initialize
|
14
|
+
# set_rank :level => 1, :to => Commiter.active do |commiter|
|
15
|
+
# commiter.repositories.count > 1 && commiter.followers >= 10
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# set_rank :level => 2, :to => Commiter.active do |commiter|
|
19
|
+
# commiter.branches.count > 1 && commiter.followers >= 10
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# set_rank :level => 3, :to => Commiter.active do |commiter|
|
23
|
+
# commiter.branches.count > 2 && commiter.followers >= 20
|
24
|
+
# end
|
25
|
+
end
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
@@ -6,8 +6,8 @@ module Merit
|
|
6
6
|
def self.included(base)
|
7
7
|
base.after_filter do |controller|
|
8
8
|
action = "#{controller_name}\##{action_name}"
|
9
|
-
badge_rules =
|
10
|
-
point_rules =
|
9
|
+
badge_rules = BadgeRules.new
|
10
|
+
point_rules = PointRules.new
|
11
11
|
if badge_rules.defined_rules[action].present? || point_rules.actions_to_point[action].present?
|
12
12
|
target_id = params[:id]
|
13
13
|
# TODO: target_object should be configurable (now it's singularized controller name)
|
data/lib/merit/rules_badge.rb
CHANGED
@@ -29,7 +29,7 @@ module Merit
|
|
29
29
|
#
|
30
30
|
# Luego chequea las condiciones sincronizadamente, o mediante un proceso en
|
31
31
|
# background, por ejemplo cada 5 minutos (Merit::BadgeRules#check_new_actions).
|
32
|
-
|
32
|
+
class BadgeRules
|
33
33
|
# Define rule for granting badges
|
34
34
|
def grant_on(action, *args, &block)
|
35
35
|
options = args.extract_options!
|
data/lib/merit/rules_points.rb
CHANGED
@@ -2,7 +2,7 @@ module Merit
|
|
2
2
|
# Points are a simple integer value which are given to "meritable" resources
|
3
3
|
# according to rules in +app/models/merit_point_rules.rb+. They are given on
|
4
4
|
# actions-triggered.
|
5
|
-
|
5
|
+
class PointRules
|
6
6
|
# Define rules on certaing actions for giving points
|
7
7
|
def score(points, *args, &block)
|
8
8
|
options = args.extract_options!
|
data/lib/merit/rules_rank.rb
CHANGED
@@ -8,7 +8,7 @@ module Merit
|
|
8
8
|
# * :+to+ model or scope to check if new rankings apply
|
9
9
|
# * :+level_name+ attribute name (default is empty and results in 'level'
|
10
10
|
# attribute, if set it's appended like 'level_#{level_name}')
|
11
|
-
|
11
|
+
class RankRules
|
12
12
|
# Populates +defined_rules+ hash with following hierarchy:
|
13
13
|
# defined_rules[ModelToRank] = { levels => blocks }
|
14
14
|
def set_rank(*args, &block)
|
data/merit.gemspec
CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.description = "Manage badges, points and rankings (reputation) of resources in a Rails application."
|
5
5
|
s.homepage = "http://github.com/tute/merit"
|
6
6
|
s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
|
7
|
-
s.version = "0.
|
7
|
+
s.version = "0.6.0"
|
8
8
|
s.authors = ["Tute Costa"]
|
9
9
|
s.email = 'tutecosta@gmail.com'
|
10
10
|
s.add_dependency 'ambry'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# +grant_on+ accepts:
|
2
|
+
# * Nothing (always grants)
|
3
|
+
# * A block which evaluates to boolean (recieves the object as parameter)
|
4
|
+
# * A block with a hash composed of methods to run on the target object with
|
5
|
+
# expected values (+:votes => 5+ for instance).
|
6
|
+
#
|
7
|
+
# +grant_on+ can have a +:to+ method name, which called over the target object
|
8
|
+
# should retrieve the object to badge (could be +:user+, +:self+, +:follower+,
|
9
|
+
# etc). If it's not defined merit will apply the badge to the user who
|
10
|
+
# triggered the action (:action_user by default). If it's :itself, it badges
|
11
|
+
# the created object (new user for instance).
|
12
|
+
#
|
13
|
+
# The :temporary option indicates that if the condition doesn't hold but the
|
14
|
+
# badge is granted, then it's removed. It's false by default (badges are kept
|
15
|
+
# forever).
|
16
|
+
|
17
|
+
module Merit
|
18
|
+
class BadgeRules
|
19
|
+
def initialize
|
20
|
+
# If it creates user, grant badge
|
21
|
+
# Should be "current_user" after registration for badge to be granted.
|
22
|
+
grant_on 'users#create', :badge => 'just-registered', :to => :itself
|
23
|
+
|
24
|
+
# If it has 10 comments, grant commenter-10 badge
|
25
|
+
grant_on 'comments#create', :badge => 'commenter', :level => 10 do |comment|
|
26
|
+
comment.user.comments.count == 10
|
27
|
+
end
|
28
|
+
|
29
|
+
# If it has at least 10 votes, grant relevant-commenter badge
|
30
|
+
grant_on 'comments#vote', :badge => 'relevant-commenter', :to => :user do |comment|
|
31
|
+
comment.votes >= 10
|
32
|
+
end
|
33
|
+
|
34
|
+
# Changes his name by one wider than 4 chars (arbitrary ruby code and custom model_name)
|
35
|
+
# This badge is temporary (user may lose it)
|
36
|
+
grant_on 'registrations#update', :badge => 'autobiographer', :temporary => true, :model_name => 'User' do |user|
|
37
|
+
user.name.length > 4
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Points are a simple integer value which are given to "meritable" resources
|
2
|
+
# according to rules in +app/models/merit_point_rules.rb+. They are given on
|
3
|
+
# actions-triggered.
|
4
|
+
|
5
|
+
module Merit
|
6
|
+
class PointRules
|
7
|
+
def initialize
|
8
|
+
score 5, :to => :user, :on => [
|
9
|
+
'comments#vote'
|
10
|
+
]
|
11
|
+
|
12
|
+
score 20, :on => [
|
13
|
+
'comments#create',
|
14
|
+
'registrations#update'
|
15
|
+
]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -8,14 +8,14 @@
|
|
8
8
|
# * :+level_name+ attribute name (default is empty and results in 'level'
|
9
9
|
# attribute, if set it's appended like 'level_#{level_name}')
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
module Merit
|
12
|
+
class RankRules
|
13
|
+
def initialize
|
14
|
+
# i stars for i chars name
|
15
|
+
(1..5).each do |i|
|
16
|
+
set_rank :level => i, :to => User do |user|
|
17
|
+
user.name.length == i
|
18
|
+
end
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -106,7 +106,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
|
|
106
106
|
|
107
107
|
user = User.where(:name => 'ab').first
|
108
108
|
assert_equal 0, user.level, "User level should be 0."
|
109
|
-
|
109
|
+
Merit::RankRules.new.check_rank_rules
|
110
110
|
user.reload
|
111
111
|
assert_equal 2, user.level, "User level should be 2."
|
112
112
|
|
@@ -116,7 +116,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
|
|
116
116
|
click_button('Update User')
|
117
117
|
|
118
118
|
user = User.where(:name => 'a').first
|
119
|
-
|
119
|
+
Merit::RankRules.new.check_rank_rules
|
120
120
|
user.reload
|
121
121
|
assert_equal 2, user.level, "User level should be 2."
|
122
122
|
|
@@ -126,7 +126,7 @@ class NavigationTest < ActiveSupport::IntegrationCase
|
|
126
126
|
click_button('Update User')
|
127
127
|
|
128
128
|
user = User.where(:name => 'abcde').first
|
129
|
-
|
129
|
+
Merit::RankRules.new.check_rank_rules
|
130
130
|
user.reload
|
131
131
|
assert_equal 5, user.level, "User level should be 5."
|
132
132
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ambry
|
16
|
-
requirement: &
|
16
|
+
requirement: &70166979392500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70166979392500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70166979391980 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.0.10
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70166979391980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70166979391560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70166979391560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: haml
|
49
|
-
requirement: &
|
49
|
+
requirement: &70166981534740 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70166981534740
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: capybara
|
60
|
-
requirement: &
|
60
|
+
requirement: &70166981531180 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70166981531180
|
69
69
|
description: Manage badges, points and rankings (reputation) of resources in a Rails
|
70
70
|
application.
|
71
71
|
email: tutecosta@gmail.com
|
@@ -112,9 +112,9 @@ files:
|
|
112
112
|
- test/dummy/app/controllers/users_controller.rb
|
113
113
|
- test/dummy/app/helpers/application_helper.rb
|
114
114
|
- test/dummy/app/models/comment.rb
|
115
|
-
- test/dummy/app/models/
|
116
|
-
- test/dummy/app/models/
|
117
|
-
- test/dummy/app/models/
|
115
|
+
- test/dummy/app/models/merit/badge_rules.rb
|
116
|
+
- test/dummy/app/models/merit/point_rules.rb
|
117
|
+
- test/dummy/app/models/merit/rank_rules.rb
|
118
118
|
- test/dummy/app/models/user.rb
|
119
119
|
- test/dummy/app/views/comments/_form.html.erb
|
120
120
|
- test/dummy/app/views/comments/edit.html.erb
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# +grant_on+ accepts:
|
2
|
-
# * Nothing (always grants)
|
3
|
-
# * A block which evaluates to boolean (recieves the object as parameter)
|
4
|
-
# * A block with a hash composed of methods to run on the target object with
|
5
|
-
# expected values (+:votes => 5+ for instance).
|
6
|
-
#
|
7
|
-
# +grant_on+ can have a +:to+ method name, which called over the target object
|
8
|
-
# should retrieve the object to badge (could be +:user+, +:self+, +:follower+,
|
9
|
-
# etc). If it's not defined merit will apply the badge to the user who
|
10
|
-
# triggered the action (:action_user by default). If it's :itself, it badges
|
11
|
-
# the created object (new user for instance).
|
12
|
-
#
|
13
|
-
# The :temporary option indicates that if the condition doesn't hold but the
|
14
|
-
# badge is granted, then it's removed. It's false by default (badges are kept
|
15
|
-
# forever).
|
16
|
-
|
17
|
-
class MeritBadgeRules
|
18
|
-
include Merit::BadgeRules
|
19
|
-
|
20
|
-
def initialize
|
21
|
-
# If it creates user, grant badge
|
22
|
-
# Should be "current_user" after registration for badge to be granted.
|
23
|
-
grant_on 'users#create', :badge => 'just-registered', :to => :itself
|
24
|
-
|
25
|
-
# If it has 10 comments, grant commenter-10 badge
|
26
|
-
grant_on 'comments#create', :badge => 'commenter', :level => 10 do |comment|
|
27
|
-
comment.user.comments.count == 10
|
28
|
-
end
|
29
|
-
|
30
|
-
# If it has at least 10 votes, grant relevant-commenter badge
|
31
|
-
grant_on 'comments#vote', :badge => 'relevant-commenter', :to => :user do |comment|
|
32
|
-
comment.votes >= 10
|
33
|
-
end
|
34
|
-
|
35
|
-
# Changes his name by one wider than 4 chars (arbitrary ruby code and custom model_name)
|
36
|
-
# This badge is temporary (user may lose it)
|
37
|
-
grant_on 'registrations#update', :badge => 'autobiographer', :temporary => true, :model_name => 'User' do |user|
|
38
|
-
user.name.length > 4
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# Points are a simple integer value which are given to "meritable" resources
|
2
|
-
# according to rules in +app/models/merit_point_rules.rb+. They are given on
|
3
|
-
# actions-triggered.
|
4
|
-
|
5
|
-
class MeritPointRules
|
6
|
-
include Merit::PointRules
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
score 5, :to => :user, :on => [
|
10
|
-
'comments#vote'
|
11
|
-
]
|
12
|
-
|
13
|
-
score 20, :on => [
|
14
|
-
'comments#create',
|
15
|
-
'registrations#update'
|
16
|
-
]
|
17
|
-
end
|
18
|
-
end
|