scorecard 0.0.1 → 0.0.2

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: 5d64b389e1a10a193f8d53fb445000f19b15b3c8
4
- data.tar.gz: 426aaad02a63b1c11904ff53f4a8f4795f895e25
3
+ metadata.gz: 06e11f730ab8af962e70b4942175fa861d736ef4
4
+ data.tar.gz: bc09ee07cb46b2ebc3de67fae7fab333166735c3
5
5
  SHA512:
6
- metadata.gz: 1de862ba8ae7f660ec7b39e03d045f676c9f5658f1057d2768562cc764c7f430632bf3be98a91d4189253c92573f8309c36545ed0a3c85b9884dac61b16bf82c
7
- data.tar.gz: 754029cc38373c33d8a3487093f3988688fbfdeec2b0dfb44e4d3dbdb88acaa01111efcec7756729b212bb89a780a4656d5227b02b19f5f37e5b5e3dd9f5355a
6
+ metadata.gz: 21dd7bb81cca83651312ac334966664ec05daaf345cc576300e2ecbbc0e6a9521534ebb70cd1e71df3a324c12298ef20ed6de30e03b9b16deaa2b3f09261175b
7
+ data.tar.gz: e23a940cdcd60c314ee23d555279bb912cb437244020d3b70357b2b06033a5cacb3f8f95d9e89a17cf48e33c2f6c4ce84799bd42d338ab32a004787e7ea7af08
data/README.md CHANGED
@@ -8,7 +8,7 @@ For anyone who comes across this, please note this is not yet feature complete,
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- gem 'scorecard'
11
+ gem 'scorecard', '0.0.2'
12
12
 
13
13
  Don't forget to bundle:
14
14
 
@@ -55,6 +55,14 @@ If you're using Sidekiq, you can push the scoring behaviour into a background wo
55
55
  Scorecard::Points.score_async :new_post, gameable: post
56
56
  ```
57
57
 
58
+ ## Results
59
+
60
+ To get the current points count for a given user:
61
+
62
+ ```ruby
63
+ Scorecard::Points.for user
64
+ ```
65
+
58
66
  ## Contributing
59
67
 
60
68
  1. Fork it
@@ -11,15 +11,15 @@ class Scorecard::Point < ActiveRecord::Base
11
11
  validates :amount, presence: true
12
12
  validates :user, presence: true
13
13
 
14
- def self.for_user(context, user)
15
- where(
16
- context: context,
17
- user_id: user.id,
18
- user_type: user.class.name
19
- )
14
+ def self.for_context(context)
15
+ where context: context
16
+ end
17
+
18
+ def self.for_user(user)
19
+ where user_id: user.id, user_type: user.class.name
20
20
  end
21
21
 
22
22
  def self.for_user_in_timeframe(context, user, timeframe)
23
- for_user(context, user).where(created_at: timeframe)
23
+ for_context(context).for_user(user).where(created_at: timeframe)
24
24
  end
25
25
  end
@@ -21,7 +21,7 @@ class Scorecard::PointRule
21
21
 
22
22
  def current_points(payload)
23
23
  if timeframe.nil?
24
- Scorecard::Point.for_user(payload[:context], payload[:user])
24
+ Scorecard::Point.for_context(payload[:context]).for_user(payload[:user])
25
25
  else
26
26
  Scorecard::Point.for_user_in_timeframe(payload[:context], payload[:user], time_range)
27
27
  end
@@ -15,4 +15,8 @@ class Scorecard::Points
15
15
 
16
16
  Scorecard::Worker.perform_async context, options.stringify_keys
17
17
  end
18
+
19
+ def self.for(user)
20
+ Scorecard::Point.for_user(user).sum(:amount)
21
+ end
18
22
  end
data/scorecard.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'scorecard'
4
- spec.version = '0.0.1'
4
+ spec.version = '0.0.2'
5
5
  spec.authors = ['Pat Allan']
6
6
  spec.email = ['pat@freelancing-gods.com']
7
7
  spec.summary = 'Rails Engine for common scorecard patterns'
@@ -109,4 +109,17 @@ describe 'Scorecard' do
109
109
  gameable_type: 'User'
110
110
  ).should_not be_empty
111
111
  end
112
+
113
+ it "returns the total points for a user" do
114
+ Scorecard.configure do |config|
115
+ config.rules.add_rule_for_points :new_user, 20
116
+ config.rules.add_rule_for_points :new_post, 30
117
+ end
118
+
119
+ user = User.create!
120
+ post = Post.create! user: user
121
+ Scorecard::Points.score :new_user, gameable: user, user: user
122
+
123
+ Scorecard::Points.for(user).should == 50
124
+ end
112
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorecard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan