merit 1.8.0 → 1.9.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2c4d73e01e95da0a10952cf3fc7da4e9d1c2685
4
- data.tar.gz: c87f93f700d5b2fa3ef5360d39e424590fa38bc8
3
+ metadata.gz: debce052338bde9db1f6ad4a50b88cbad2cdd466
4
+ data.tar.gz: 3c41c3c3ce1df213836fdb4f708425cc83fb9ec6
5
5
  SHA512:
6
- metadata.gz: ecb5d0edb9dcce2e28315b4801e369ca03e799761db94ceff31402b95cb236d3a983618e0a1761dbd504d00c1825df751b48553c55a2703effe12907a873a1af
7
- data.tar.gz: 6f18fef800b516684098b70392c3eb606793c2b7fefec4a00185e8311897b6dbb835dfae31ef8bc06cea883205096d7078b178452b03c830c34fdfb9fc5888d5
6
+ metadata.gz: ccb24cf9023b3aa519e9e265379a57864176019a63cfde2253fc145b82a58fe402fc0ffe2963b7f43ec9ab5242d26819d10e7814743c62e2aa435e2a91b427d3
7
+ data.tar.gz: e77bf853ca0b6ca140f57a04fe32d3e0c6499cc13027e4a413514967afabb3544d6dc7bb9babd5fe84b5cf382bfe242a0bff222a2121be543ae13fdb08af27cd
data/README.md CHANGED
@@ -57,12 +57,12 @@ Create badges in `config/initializers/merit.rb`
57
57
  ### Example
58
58
 
59
59
  ```ruby
60
- Merit::Badge.create! ({
60
+ Merit::Badge.create!(
61
61
  id: 1,
62
62
  name: "Yearling",
63
63
  description: "Active member for a year",
64
64
  custom_fields: { difficulty: :silver }
65
- })
65
+ )
66
66
  ```
67
67
 
68
68
  ## Defining Rules
@@ -122,12 +122,6 @@ current_user.rm_badge(badge.id)
122
122
  ```
123
123
 
124
124
  ```ruby
125
- # List 10 badge grants in the last month
126
- Badge.last_granted
127
-
128
- # List 20 badge grants in the last week
129
- Badge.last_granted(since_date: 1.week.ago, limit: 20)
130
-
131
125
  # Get related entries of a given badge
132
126
  Badge.find(1).users
133
127
  ```
@@ -192,7 +186,7 @@ score proc, on: 'photos#create'
192
186
 
193
187
  ```ruby
194
188
  # Score manually
195
- current_user.add_points(20, 'Optional log message')
189
+ current_user.add_points(20)
196
190
  current_user.subtract_points(10)
197
191
  ```
198
192
 
@@ -200,16 +194,6 @@ current_user.subtract_points(10)
200
194
  # Query awarded points since a given date
201
195
  score_points = current_user.sash.scores.first.score_points
202
196
  score_points.where("created_at > '#{1.month.ago}'").sum(:num_points)
203
-
204
- # List top 10 scored users in the last month
205
- Merit::Score.top_scored
206
-
207
- # List top 25 scored lists in the last week
208
- Merit::Score.top_scored(
209
- table_name: :lists,
210
- since_date: 1.week.ago,
211
- limit: 25
212
- )
213
197
  ```
214
198
 
215
199
  ## Displaying Points
@@ -307,5 +291,6 @@ config.add_observer 'ReputationChangeObserver'
307
291
 
308
292
  # To-do List
309
293
 
294
+ ## Pre 2.0.0
295
+
310
296
  * Move level from meritable model into Sash
311
- * `ActivityLog` should replace `add_points` `log` parameter
@@ -1,4 +1,19 @@
1
- # Upgrading
1
+ # Main Changes / Upgrading Notes
2
+
3
+ ## 1.9.0 (not released yet)
4
+
5
+ * Deprecates `Merit::Badge.last_granted` and `Merit::Score.top_scored`.
6
+ Code can be readded to client applications following instructions in:
7
+ https://github.com/tute/merit/wiki/How-to-show-a-points-leaderboard
8
+ https://github.com/tute/merit/wiki/How-to-show-last-granted-badges
9
+ * Deprecates `add_points` `log` parameter.
10
+
11
+ ## 1.8.0
12
+
13
+ * Completes implementation of observer patter for getting reputation grant
14
+ notifications to the client app. See: https://github.com/tute/merit#getting-
15
+ notifications.
16
+ * Work on mongoid adapter (not yet ready), and other internals polishing.
2
17
 
3
18
  ## 1.7.0
4
19
 
@@ -31,16 +31,11 @@ module Merit
31
31
 
32
32
  def check_rules(rules_array, badges_or_points)
33
33
  rules_array.each do |rule|
34
- judge = Judge.new sashes_to_badge(rule), rule, action: self
34
+ judge = Judge.new rule, action: self
35
35
  judge.send :"apply_#{badges_or_points}"
36
36
  end
37
37
  end
38
38
 
39
- # Subject to badge: source_user or target.user?
40
- def sashes_to_badge(rule)
41
- SashFinder.find(rule, self)
42
- end
43
-
44
39
  # Mark merit_action as processed
45
40
  def processed!
46
41
  self.processed = true
@@ -37,8 +37,10 @@ module Merit
37
37
  badge
38
38
  end
39
39
 
40
- # Last badges granted
40
+ # DEPRECATED: `last_granted` will be removed from merit, please refer to:
41
+ # https://github.com/tute/merit/wiki/How-to-show-last-granted-badges
41
42
  def last_granted(options = {})
43
+ warn '[merit] [DEPRECATION] `last_granted` will be removed from merit, please refer to: https://github.com/tute/merit/wiki/How-to-show-last-granted-badges'
42
44
  options[:since_date] ||= 1.month.ago
43
45
  options[:limit] ||= 10
44
46
  BadgesSash.last_granted(options)
@@ -4,13 +4,9 @@ module Merit
4
4
  class Judge
5
5
  include Observable
6
6
 
7
- def initialize(sashes, rule, options = {})
8
- @sashes = sashes
7
+ def initialize(rule, options = {})
9
8
  @rule = rule
10
- # FIXME: Too much context?
11
- # A Judge should apply reputation independently of the action
12
9
  @action = options[:action]
13
-
14
10
  Merit.observers.each do |class_name|
15
11
  add_observer class_name.constantize.new
16
12
  end
@@ -28,7 +24,7 @@ module Merit
28
24
 
29
25
  def apply_points
30
26
  return unless rule_applies?
31
- @sashes.each do |sash|
27
+ sashes.each do |sash|
32
28
  point = sash.add_points points
33
29
  notify_observers(
34
30
  description: "granted #{points} points",
@@ -41,7 +37,7 @@ module Merit
41
37
  private
42
38
 
43
39
  def grant_badges
44
- @sashes.each do |sash|
40
+ sashes.each do |sash|
45
41
  next unless new_or_multiple?(sash)
46
42
  badge_sash = sash.add_badge badge.id
47
43
  notify_observers(
@@ -53,7 +49,7 @@ module Merit
53
49
  end
54
50
 
55
51
  def remove_badges
56
- @sashes.each do |sash|
52
+ sashes.each do |sash|
57
53
  badge_sash = sash.rm_badge badge.id
58
54
  notify_observers(
59
55
  description: "removed #{badge.name} badge",
@@ -83,6 +79,10 @@ module Merit
83
79
  end
84
80
  end
85
81
 
82
+ def sashes
83
+ @sashes ||= SashFinder.find @rule, @action
84
+ end
85
+
86
86
  def badge
87
87
  @rule.badge
88
88
  end
@@ -9,7 +9,10 @@ module Merit
9
9
  attr_accessible :badge_id
10
10
  end
11
11
 
12
+ # DEPRECATED: `last_granted` will be removed from merit, please refer to:
13
+ # https://github.com/tute/merit/wiki/How-to-show-last-granted-badges
12
14
  def self.last_granted(options = {})
15
+ warn '[merit] [DEPRECATION] `last_granted` will be removed from merit, please refer to: https://github.com/tute/merit/wiki/How-to-show-last-granted-badges'
13
16
  options[:since_date] ||= 1.month.ago
14
17
  options[:limit] ||= 10
15
18
  where("created_at > '#{options[:since_date]}'")
@@ -6,13 +6,10 @@ module Merit
6
6
  dependent: :destroy,
7
7
  class_name: 'Merit::Score::Point'
8
8
 
9
- # Meant to display a leaderboard. Accepts options :table_name (users by
10
- # default), :since_date (1.month.ago by default) and :limit (10 by
11
- # default).
12
- #
13
- # It lists top 10 scored objects in the last month, unless you change
14
- # query parameters.
9
+ # DEPRECATED: `top_scored` will be removed from merit, please refer to:
10
+ # https://github.com/tute/merit/wiki/How-to-show-a-points-leaderboard
15
11
  def self.top_scored(options = {})
12
+ warn '[merit] [DEPRECATION] `top_scored` will be removed from merit, please refer to: https://github.com/tute/merit/wiki/How-to-show-a-points-leaderboard'
16
13
  options[:table_name] ||= :users
17
14
  options[:since_date] ||= 1.month.ago
18
15
  options[:limit] ||= 10
@@ -15,6 +15,9 @@ module Merit
15
15
  end
16
16
 
17
17
  def add_points(num_points, log = 'Manually granted', category = 'default')
18
+ if log != 'Manually granted'
19
+ warn '[merit] [DEPRECATION] `add_points` `log` parameter is deprecated'
20
+ end
18
21
  point = Merit::Score::Point.new
19
22
  point.log = log
20
23
  point.num_points = num_points
@@ -24,7 +27,7 @@ module Merit
24
27
 
25
28
  # DEPRECATED: Please use <tt>subtract_points</tt> instead.
26
29
  def substract_points(num_points, log = 'Manually granted', category = 'default')
27
- warn '[DEPRECATION] `substract_points` is deprecated. Please use `subtract_points` instead.'
30
+ warn '[merit] [DEPRECATION] `substract_points` is deprecated. Please use `subtract_points` instead.'
28
31
  subtract_points num_points, log, category
29
32
  end
30
33
 
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
5
5
  s.homepage = "http://github.com/tute/merit"
6
6
  s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
7
7
  s.license = 'MIT'
8
- s.version = '1.8.0'
8
+ s.version = '1.9.0'
9
9
  s.authors = ["Tute Costa"]
10
10
  s.email = 'tutecosta@gmail.com'
11
11
 
@@ -0,0 +1,14 @@
1
+ case Merit.orm
2
+ when :active_record
3
+ class Address < ActiveRecord::Base
4
+ end
5
+ when :mongoid
6
+ class Address
7
+ include Mongoid::Document
8
+ include Mongoid::Timestamps
9
+ end
10
+ end
11
+
12
+ class Address
13
+ belongs_to :user
14
+ end
@@ -26,6 +26,13 @@ module Merit
26
26
  true
27
27
  end
28
28
 
29
+ # For regression test: if condition doesn't hold, it doesn't check
30
+ # sashes to badge. Useful for polymorphic relations where not every
31
+ # model has reputation. See https://github.com/tute/merit/issues/134.
32
+ grant_on 'users#create', badge: 'just-registered', to: :model_with_no_reputation do |user|
33
+ user.model_with_no_reputation.respond_to?(:_sash)
34
+ end
35
+
29
36
  # Example rule for multiple badge granting
30
37
  grant_on 'users#index', badge: 'gossip', multiple: true
31
38
 
@@ -14,12 +14,17 @@ end
14
14
  class User
15
15
  has_merit
16
16
 
17
+ has_many :addresses
17
18
  has_many :comments
18
19
 
19
20
  if defined?(ProtectedAttributes) || !defined?(ActionController::StrongParameters)
20
21
  attr_accessible :name
21
22
  end
22
23
 
24
+ def model_with_no_reputation
25
+ addresses.first || addresses.create
26
+ end
27
+
23
28
  def show_badges
24
29
  badges_uniq = Badge.find_by_id(badge_ids)
25
30
  badges_uniq.collect{|b| "#{b.name.capitalize}#{badge_status(b)}" }.join(', ')
@@ -0,0 +1,11 @@
1
+ class CreateAddresses < ActiveRecord::Migration
2
+ def up
3
+ create_table :addresses do |t|
4
+ t.references :user
5
+ end
6
+ end
7
+
8
+ def down
9
+ drop_table :addresses
10
+ end
11
+ end
@@ -11,7 +11,11 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20130329224410) do
14
+ ActiveRecord::Schema.define(:version => 20140211144001) do
15
+
16
+ create_table "addresses", :force => true do |t|
17
+ t.integer "user_id"
18
+ end
15
19
 
16
20
  create_table "badges_sashes", :force => true do |t|
17
21
  t.integer "badge_id"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tute Costa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-09 00:00:00.000000000 Z
11
+ date: 2014-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ambry
@@ -177,6 +177,7 @@ files:
177
177
  - test/dummy/app/controllers/registrations_controller.rb
178
178
  - test/dummy/app/controllers/users_controller.rb
179
179
  - test/dummy/app/helpers/application_helper.rb
180
+ - test/dummy/app/models/address.rb
180
181
  - test/dummy/app/models/comment.rb
181
182
  - test/dummy/app/models/dummy_observer.rb
182
183
  - test/dummy/app/models/merit/badge_rules.rb
@@ -221,6 +222,7 @@ files:
221
222
  - test/dummy/db/migrate/20130329224408_create_sashes.rb
222
223
  - test/dummy/db/migrate/20130329224409_create_badges_sashes.rb
223
224
  - test/dummy/db/migrate/20130329224410_create_scores_and_points.rb
225
+ - test/dummy/db/migrate/20140211144001_create_addresses.rb
224
226
  - test/dummy/db/schema.rb
225
227
  - test/dummy/db/seeds.rb
226
228
  - test/dummy/public/404.html