merit 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- merit (1.0.0)
4
+ merit (1.0.1)
5
5
  ambry (~> 0.3.0)
6
6
 
7
7
  GEM
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 a simple integer value which are given to "meritable" resources.
78
- They are given on actions-triggered, either to the action user or to the
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
- `:to` method(s) work as in badge rules: they are sent to the target_object.
94
- In the following example, after a review gets created both `review.reviewer`
95
- and `review.reviewed` are granted 15 points:
103
+ ## Score manually
104
+
105
+ You may also change user points "by hand":
96
106
 
97
107
  ```ruby
98
- score 15, :on => 'reviews#create', :to => [:reviewer, :reviewed]
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,5 +1,9 @@
1
1
  # Upgrading
2
2
 
3
+ ## to 1.0.1
4
+
5
+ Adds Merit::Point#created_at attribute.
6
+
3
7
  ## to 1.0.0
4
8
 
5
9
  Points granting history is now logged.
@@ -9,6 +9,7 @@ class CreateScoresAndPoints < ActiveRecord::Migration
9
9
  t.references :score
10
10
  t.integer :num_points, :default => 0
11
11
  t.string :log
12
+ t.datetime :created_at
12
13
  end
13
14
  end
14
15
 
@@ -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/merit_point_rules.rb+. They are given on
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
- # 'users#update'
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
  #
@@ -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/merit_rules.rb, con la siguiente sintaxis:
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
@@ -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/merit_point_rules.rb+. They are given on
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.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/merit_point_rules.rb+. They are given on
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/merit_point_rules.rb+. They are given on
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
@@ -9,6 +9,7 @@ class CreateScoresAndPoints < ActiveRecord::Migration
9
9
  t.references :score
10
10
  t.integer :num_points, :default => 0
11
11
  t.string :log
12
+ t.datetime :created_at
12
13
  end
13
14
  end
14
15
 
@@ -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 "score_id"
51
- t.integer "num_points", :default => 0
52
- t.string "log"
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|
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: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: