merit 1.0.0 → 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.
- data/Gemfile.lock +1 -1
- data/README.md +21 -10
- data/UPGRADING.md +4 -0
- data/lib/generators/active_record/templates/create_scores_and_points.rb +1 -0
- data/lib/generators/merit/templates/merit_point_rules.rb +7 -4
- data/lib/merit/rules_badge.rb +1 -1
- data/lib/merit/rules_points.rb +1 -1
- data/merit.gemspec +1 -1
- data/test/dummy-mongoid/app/models/merit/point_rules.rb +1 -1
- data/test/dummy/app/models/merit/point_rules.rb +1 -1
- data/test/dummy/db/migrate/20121013174256_create_scores_and_points.rb +1 -0
- data/test/dummy/db/schema.rb +4 -3
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -45,7 +45,6 @@ holds. Badges may have levels, and may be temporary. Define rules on
|
|
45
45
|
|
46
46
|
## Examples
|
47
47
|
|
48
|
-
|
49
48
|
```ruby
|
50
49
|
grant_on 'comments#vote', :badge => 'relevant-commenter', :to => :user do |comment|
|
51
50
|
comment.votes.count == 5
|
@@ -74,28 +73,41 @@ Badge.find(3).delete_from(current_user)
|
|
74
73
|
|
75
74
|
# Defining point rules
|
76
75
|
|
77
|
-
Points are
|
78
|
-
|
79
|
-
method(s) defined in the `:to` option. Define rules on
|
76
|
+
Points are given to "meritable" resources on actions-triggered, either to the
|
77
|
+
action user or to the method(s) defined in the `:to` option. Define rules on
|
80
78
|
`app/models/merit/point_rules.rb`:
|
81
79
|
|
80
|
+
`score` accepts:
|
81
|
+
|
82
|
+
* `:on` action as string or array of strings (similar to Rails routes)
|
83
|
+
* `:to` method(s) to send to the target_object (who should be scored?)
|
84
|
+
* `&block`
|
85
|
+
* empty (always scores)
|
86
|
+
* a block which evaluates to boolean (recieves target object as parameter)
|
87
|
+
|
82
88
|
## Examples
|
83
89
|
|
84
90
|
```ruby
|
85
|
-
score 10, :to => :post_creator, :on => 'comments#create'
|
91
|
+
score 10, :to => :post_creator, :on => 'comments#create' do |comment|
|
92
|
+
comment.title.present?
|
93
|
+
end
|
86
94
|
|
87
95
|
score 20, :on => [
|
88
96
|
'comments#create',
|
89
97
|
'photos#create'
|
90
98
|
]
|
99
|
+
|
100
|
+
score 15, :on => 'reviews#create', :to => [:reviewer, :reviewed]
|
91
101
|
```
|
92
102
|
|
93
|
-
|
94
|
-
|
95
|
-
|
103
|
+
## Score manually
|
104
|
+
|
105
|
+
You may also change user points "by hand":
|
96
106
|
|
97
107
|
```ruby
|
98
|
-
|
108
|
+
current_user.add_points(20, 'Optional log message')
|
109
|
+
|
110
|
+
current_user.substract_points(10)
|
99
111
|
```
|
100
112
|
|
101
113
|
---
|
@@ -146,4 +158,3 @@ end
|
|
146
158
|
* :value parameter (for star voting for example) should be configurable
|
147
159
|
(depends on params[:value] on the controller).
|
148
160
|
* Make fixtures for integration testing (now creating objects on test file!).
|
149
|
-
* Rules should be cached? Calling *Rules.new more than once
|
data/UPGRADING.md
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
# Points are a simple integer value which are given to "meritable" resources
|
2
|
-
# according to rules in +app/models/
|
2
|
+
# according to rules in +app/models/merit/point_rules.rb+. They are given on
|
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
|
+
#
|
6
|
+
# 'score' method may accept a block which evaluates to boolean
|
7
|
+
# (recieves the object as parameter)
|
5
8
|
|
6
9
|
module Merit
|
7
10
|
class PointRules
|
8
11
|
include Merit::PointRulesMethods
|
9
12
|
|
10
13
|
def initialize
|
11
|
-
# score 10, :on =>
|
12
|
-
#
|
13
|
-
#
|
14
|
+
# score 10, :on => 'users#update' do
|
15
|
+
# user.name.present?
|
16
|
+
# end
|
14
17
|
#
|
15
18
|
# score 15, :on => 'reviews#create', :to => [:reviewer, :reviewed]
|
16
19
|
#
|
data/lib/merit/rules_badge.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Merit
|
2
2
|
# La configuración para especificar cuándo aplicar cada badge va en
|
3
|
-
# app/models/
|
3
|
+
# app/models/merit/badge_rules.rb, con la siguiente sintaxis:
|
4
4
|
#
|
5
5
|
# grant_on 'users#create', :badge => 'just', :level => 'registered' do
|
6
6
|
# # Nothing, or code block which evaluates to boolean
|
data/lib/merit/rules_points.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Merit
|
2
2
|
# Points are a simple integer value which are given to "meritable" resources
|
3
|
-
# according to rules in +app/models/
|
3
|
+
# according to rules in +app/models/merit/point_rules.rb+. They are given on
|
4
4
|
# actions-triggered.
|
5
5
|
module PointRulesMethods
|
6
6
|
# Define rules on certaing actions for giving points
|
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 = '1.0.
|
7
|
+
s.version = '1.0.1'
|
8
8
|
s.authors = ["Tute Costa"]
|
9
9
|
s.email = 'tutecosta@gmail.com'
|
10
10
|
s.add_dependency 'ambry', '~> 0.3.0'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Points are a simple integer value which are given to "meritable" resources
|
2
|
-
# according to rules in +app/models/
|
2
|
+
# according to rules in +app/models/merit/point_rules.rb+. They are given on
|
3
3
|
# actions-triggered.
|
4
4
|
|
5
5
|
module Merit
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Points are a simple integer value which are given to "meritable" resources
|
2
|
-
# according to rules in +app/models/
|
2
|
+
# according to rules in +app/models/merit/point_rules.rb+. They are given on
|
3
3
|
# actions-triggered.
|
4
4
|
|
5
5
|
module Merit
|
data/test/dummy/db/schema.rb
CHANGED
@@ -47,9 +47,10 @@ ActiveRecord::Schema.define(:version => 20121013174256) do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
create_table "merit_score_points", :force => true do |t|
|
50
|
-
t.integer
|
51
|
-
t.integer
|
52
|
-
t.string
|
50
|
+
t.integer "score_id"
|
51
|
+
t.integer "num_points", :default => 0
|
52
|
+
t.string "log"
|
53
|
+
t.datetime "created_at"
|
53
54
|
end
|
54
55
|
|
55
56
|
create_table "merit_scores", :force => true do |t|
|