scorecard 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/app/models/scorecard/point.rb +7 -7
- data/lib/scorecard/point_rule.rb +1 -1
- data/lib/scorecard/points.rb +4 -0
- data/scorecard.gemspec +1 -1
- data/spec/acceptance/points_spec.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06e11f730ab8af962e70b4942175fa861d736ef4
|
4
|
+
data.tar.gz: bc09ee07cb46b2ebc3de67fae7fab333166735c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
15
|
-
where
|
16
|
-
|
17
|
-
|
18
|
-
|
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(
|
23
|
+
for_context(context).for_user(user).where(created_at: timeframe)
|
24
24
|
end
|
25
25
|
end
|
data/lib/scorecard/point_rule.rb
CHANGED
@@ -21,7 +21,7 @@ class Scorecard::PointRule
|
|
21
21
|
|
22
22
|
def current_points(payload)
|
23
23
|
if timeframe.nil?
|
24
|
-
Scorecard::Point.
|
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
|
data/lib/scorecard/points.rb
CHANGED
data/scorecard.gemspec
CHANGED
@@ -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
|