session_tracker 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -32,6 +32,8 @@ Then to view the current state:
32
32
 
33
33
  If redis is accessible through $redis, you don't have to give it as an argument to SessionTracker.new.
34
34
 
35
+ Read the spec and/or code to see how it works.
36
+
35
37
  ## Contributing
36
38
 
37
39
  1. Fork it
@@ -1,3 +1,3 @@
1
1
  class SessionTracker
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -18,14 +18,14 @@ class SessionTracker
18
18
  # so we don't want to raise errors just because redis is down for a few seconds.
19
19
  end
20
20
 
21
- def active_users(time = Time.now)
22
- @redis.sunion(*keys_for_last_3_minutes(time)).size
21
+ def active_users(timespan_in_minutes = 5, time = Time.now)
22
+ @redis.sunion(*keys_within(timespan_in_minutes, time)).size
23
23
  end
24
24
 
25
25
  private
26
26
 
27
- def keys_for_last_3_minutes(time)
28
- times = 0.upto(2).map { |n| time - (n * 60) }
27
+ def keys_within(minutes, time)
28
+ times = 0.upto(minutes - 1).map { |n| time - (n * 60) }
29
29
  times.map { |t| key_for(t) }
30
30
  end
31
31
 
@@ -44,14 +44,21 @@ describe SessionTracker, "active_users" do
44
44
 
45
45
  let(:redis) { mock.as_null_object }
46
46
 
47
- it "should do a union on the last 3 minutes to get a active user count" do
47
+ it "should do a union on the last 5 minutes to get a active user count" do
48
48
  time = Time.parse("13:09")
49
49
  redis.should_receive(:sunion).with("active_customer_sessions_minute_09",
50
50
  "active_customer_sessions_minute_08",
51
51
  "active_customer_sessions_minute_07").
52
52
  and_return([ mock, mock ])
53
53
 
54
- SessionTracker.new("customer", redis).active_users(time).should == 2
54
+ SessionTracker.new("customer", redis).active_users(3, time).should == 2
55
+ end
56
+
57
+ it "should use a default time span of 5 minutes" do
58
+ redis.should_receive(:sunion).with(anything, anything, anything,
59
+ anything, anything).and_return([ mock, mock ])
60
+
61
+ SessionTracker.new("customer", redis).active_users.should == 2
55
62
  end
56
63
 
57
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: session_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &2160370920 !ruby/object:Gem::Requirement
16
+ requirement: &2156132780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2160370920
24
+ version_requirements: *2156132780
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2160370440 !ruby/object:Gem::Requirement
27
+ requirement: &2156132280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2160370440
35
+ version_requirements: *2156132280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: guard
38
- requirement: &2160370020 !ruby/object:Gem::Requirement
38
+ requirement: &2156131740 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2160370020
46
+ version_requirements: *2156131740
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-rspec
49
- requirement: &2160369580 !ruby/object:Gem::Requirement
49
+ requirement: &2156131260 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2160369580
57
+ version_requirements: *2156131260
58
58
  description: Track active user sessions in redis
59
59
  email:
60
60
  - joakim.kolsjo@gmail.com