gamifier 1.0.6 → 1.0.7
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.
@@ -2,15 +2,29 @@ require 'gamifier/model'
|
|
2
2
|
|
3
3
|
module Gamifier
|
4
4
|
class ActivityDefinition < Model
|
5
|
-
|
5
|
+
|
6
|
+
def limit(n_times, over_time)
|
6
7
|
self.enable_rate_limiting = true
|
7
|
-
self.bucket_max_capacity =
|
8
|
-
self.bucket_drain_rate =
|
8
|
+
self.bucket_max_capacity = n_times
|
9
|
+
self.bucket_drain_rate = n_times.to_f / over_time.to_f
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def limit_per_day(times_per_day)
|
14
|
+
limit(times_per_day, 24.0)
|
15
|
+
end
|
16
|
+
|
17
|
+
def limit_per_week(times_per_week)
|
18
|
+
limit(times_per_week, 24.0 * 7.0)
|
9
19
|
end
|
10
20
|
|
11
21
|
def limit_once_per_day
|
12
22
|
limit_per_day 1
|
13
23
|
end
|
14
24
|
|
25
|
+
def limit_once_per_week
|
26
|
+
limit_per_week 1
|
27
|
+
end
|
28
|
+
|
15
29
|
end
|
16
|
-
end
|
30
|
+
end
|
data/lib/gamifier/version.rb
CHANGED
@@ -1,24 +1,59 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gamifier::Player do
|
4
|
+
|
4
5
|
before do
|
5
6
|
@engine = mock(Gamifier::Engine)
|
6
7
|
end
|
7
|
-
describe "limit_per_day" do
|
8
|
-
it "should set rate limits" do
|
9
|
-
a = Gamifier::ActivityDefinition.new
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
describe ".limit" do
|
10
|
+
|
11
|
+
subject { Gamifier::ActivityDefinition.new.limit(1, 24.0) }
|
12
|
+
|
13
|
+
it { subject.enable_rate_limiting.should be_true }
|
14
|
+
it { subject.bucket_max_capacity.should == 1 }
|
15
|
+
it { subject.bucket_drain_rate.should == 1 / 24.0 }
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".limit_per_day" do
|
20
|
+
|
21
|
+
subject { Gamifier::ActivityDefinition.new.limit_per_day(1) }
|
22
|
+
|
23
|
+
it { subject.enable_rate_limiting.should be_true }
|
24
|
+
it { subject.bucket_max_capacity.should == 1 }
|
25
|
+
it { subject.bucket_drain_rate.should == 1 / 24.0 }
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".limit_per_week" do
|
30
|
+
|
31
|
+
subject { Gamifier::ActivityDefinition.new.limit_per_week(1) }
|
32
|
+
|
33
|
+
it { subject.enable_rate_limiting.should be_true }
|
34
|
+
it { subject.bucket_max_capacity.should == 1 }
|
35
|
+
it { subject.bucket_drain_rate.should == 1 / (24.0 * 7.0) }
|
13
36
|
|
14
|
-
end
|
15
37
|
end
|
16
38
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
39
|
+
describe ".limit_once_per_day" do
|
40
|
+
|
41
|
+
subject { Gamifier::ActivityDefinition.new.limit_once_per_day }
|
42
|
+
|
43
|
+
it { subject.enable_rate_limiting.should be_true }
|
44
|
+
it { subject.bucket_max_capacity.should == 1 }
|
45
|
+
it { subject.bucket_drain_rate.should == 1 / 24.0 }
|
46
|
+
|
23
47
|
end
|
48
|
+
|
49
|
+
describe ".limit_once_per_week" do
|
50
|
+
|
51
|
+
subject { Gamifier::ActivityDefinition.new.limit_once_per_week }
|
52
|
+
|
53
|
+
it { subject.enable_rate_limiting.should be_true }
|
54
|
+
it { subject.bucket_max_capacity.should == 1 }
|
55
|
+
it { subject.bucket_drain_rate.should == 1 / (24.0 * 7.0) }
|
56
|
+
|
57
|
+
end
|
58
|
+
|
24
59
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gamifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 7
|
10
|
+
version: 1.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Cyril Rohr
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-09-
|
18
|
+
date: 2012-09-26 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: faraday
|