leaderboard 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## leaderboard 2.3.0 (2012-07-09)
4
+
5
+ * Added `expire_leaderboard(seconds)` to expire the leaderboard in a set number of seconds.
6
+ * Added `expire_leaderboard_at(timestamp)` to expire the leaderboard at a specific UNIX timestamp.
7
+ * Added optional `page_size` parameter to the `total_pages` method.
8
+
3
9
  ## leaderboard 2.2.1 (2012-06-18)
4
10
 
5
11
  * Fix for #17 - Leaderboard not compatible with redis 2.1.1. Redis' `zrangebyscore` and `zrevrangebyscore` methods do not return scores by default. No need to pass the option in the initial call.
@@ -40,16 +46,16 @@
40
46
 
41
47
  * Allow for only single options to be passed to `leaders`, `around_me` and `ranked_in_list` methods - https://github.com/agoragames/leaderboard/issues/4
42
48
  * Added `percentile_for(member)` and `percentile_for_in(leaderboard_name, member)` methods to calculate percentile for a given member
43
-
49
+
44
50
  ## leaderboard 2.0.0 (2011-08-05)
45
-
51
+
46
52
  * Change `add_member` to `rank_member` - https://github.com/agoragames/leaderboard/issues/3
47
53
  * Added `delete_leaderboard` and `delete_leaderboard_named` - https://github.com/agoragames/leaderboard/issues/2
48
54
  * Ability to pass in an existing Redis connection in initializer - https://github.com/agoragames/leaderboard/issues/1
49
55
  * Added transaction support for `score_and_rank_for`, `leaders`, `around_me` and `ranked_in_list`
50
56
  * Updated initializer to take a leaderboard name, `options` hash and `redis_options` hash
51
57
  * Simplified `leaders`, `around_me` and `ranked_in_list` to use an `options` hash with defaults for the previously individual parameters
52
-
58
+
53
59
  ## leaderboard 1.0.6 (unreleased)
54
60
 
55
61
  * Added `disconnect` method
@@ -69,7 +75,7 @@
69
75
 
70
76
  * Fixing issue using total_pages in leaderboard_in call
71
77
  * Internal `massage_leader_data` method will now respect `with_scores`
72
-
78
+
73
79
  ## leaderboard 1.0.2 (2011-02-25)
74
80
 
75
81
  * Adding `XXX_to`, `XXX_for`, `XXX_in` and `XXX_from` methods that will allow you to set the leaderboard name to interact with outside of creating a new object
@@ -252,6 +252,8 @@ Use this method to do bulk insert of data, but be mindful of the amount of data
252
252
  remove_members_in_score_range(min_score, max_score): Remove members from the leaderboard within a score range
253
253
  percentile_for(member): Calculate the percentile for a given member
254
254
  page_for(member, page_size): Determine the page where a member falls in the leaderboard
255
+ expire_leaderboard(seconds): Expire the leaderboard in a set number of seconds.
256
+ expire_leaderboard_at(timestamp): Expire the leaderboard at a specific UNIX timestamp.
255
257
  rank_members(members_and_scores): Rank an array of members in the leaderboard where you can call via (member_name, score) or pass in an array of [member_name, score]
256
258
  merge_leaderboards(destination, keys, options = {:aggregate => :min}): Merge leaderboards given by keys with this leaderboard into destination
257
259
  intersect_leaderboards(destination, keys, options = {:aggregate => :min}): Intersect leaderboards given by keys with this leaderboard into destination
@@ -240,15 +240,17 @@ class Leaderboard
240
240
 
241
241
  # Retrieve the total number of pages in the leaderboard.
242
242
  #
243
+ # @param page_size [int, nil] Page size to be used when calculating the total number of pages.
244
+ #
243
245
  # @return the total number of pages in the leaderboard.
244
- def total_pages
245
- total_pages_in(@leaderboard_name)
246
+ def total_pages(page_size = nil)
247
+ total_pages_in(@leaderboard_name, page_size)
246
248
  end
247
249
 
248
250
  # Retrieve the total number of pages in the named leaderboard.
249
251
  #
250
252
  # @param leaderboard_name [String] Name of the leaderboard.
251
- # @param page_size [int] Page size to be used when paging through the leaderboard.
253
+ # @param page_size [int, nil] Page size to be used when calculating the total number of pages.
252
254
  #
253
255
  # @return the total number of pages in the named leaderboard.
254
256
  def total_pages_in(leaderboard_name, page_size = nil)
@@ -478,6 +480,44 @@ class Leaderboard
478
480
 
479
481
  (rank_for_member.to_f / page_size.to_f).ceil
480
482
  end
483
+
484
+ # Expire the current leaderboard in a set number of seconds. Do not use this with
485
+ # leaderboards that utilize member data as there is no facility to cascade the
486
+ # expiration out to the keys for the member data.
487
+ #
488
+ # @param seconds [int] Number of seconds after which the leaderboard will be expired.
489
+ def expire_leaderboard(seconds)
490
+ expire_leaderboard_for(@leaderboard_name, seconds)
491
+ end
492
+
493
+ # Expire the given leaderboard in a set number of seconds. Do not use this with
494
+ # leaderboards that utilize member data as there is no facility to cascade the
495
+ # expiration out to the keys for the member data.
496
+ #
497
+ # @param leaderboard_name [String] Name of the leaderboard.
498
+ # @param seconds [int] Number of seconds after which the leaderboard will be expired.
499
+ def expire_leaderboard_for(leaderboard_name, seconds)
500
+ @redis_connection.expire(leaderboard_name, seconds)
501
+ end
502
+
503
+ # Expire the current leaderboard at a specific UNIX timestamp. Do not use this with
504
+ # leaderboards that utilize member data as there is no facility to cascade the
505
+ # expiration out to the keys for the member data.
506
+ #
507
+ # @param timestamp [int] UNIX timestamp at which the leaderboard will be expired.
508
+ def expire_leaderboard_at(timestamp)
509
+ expire_leaderboard_at_for(@leaderboard_name, timestamp)
510
+ end
511
+
512
+ # Expire the given leaderboard at a specific UNIX timestamp. Do not use this with
513
+ # leaderboards that utilize member data as there is no facility to cascade the
514
+ # expiration out to the keys for the member data.
515
+ #
516
+ # @param leaderboard_name [String] Name of the leaderboard.
517
+ # @param timestamp [int] UNIX timestamp at which the leaderboard will be expired.
518
+ def expire_leaderboard_at_for(leaderboard_name, timestamp)
519
+ @redis_connection.expireat(leaderboard_name, timestamp)
520
+ end
481
521
 
482
522
  # Retrieve a page of leaders from the leaderboard.
483
523
  #
@@ -1,4 +1,4 @@
1
1
  class Leaderboard
2
2
  # Leaderboard version
3
- VERSION = '2.2.1'.freeze
3
+ VERSION = '2.3.0'.freeze
4
4
  end
@@ -80,6 +80,7 @@ describe 'Leaderboard' do
80
80
  rank_members_in_leaderboard(10)
81
81
 
82
82
  @leaderboard.total_pages.should be(1)
83
+ @leaderboard.total_pages(5).should be(2)
83
84
 
84
85
  @redis_connection.flushdb
85
86
 
@@ -546,6 +547,26 @@ describe 'Leaderboard' do
546
547
  @leaderboard.page_for('member_1', 10).should be(2)
547
548
  end
548
549
 
550
+ it 'should set an expire on the leaderboard' do
551
+ rank_members_in_leaderboard
552
+
553
+ @leaderboard.expire_leaderboard(3)
554
+ @redis_connection.ttl(@leaderboard.leaderboard_name).tap do |ttl|
555
+ ttl.should be > 1
556
+ ttl.should be <= 3
557
+ end
558
+ end
559
+
560
+ it 'should set an expire on the leaderboard using a timestamp' do
561
+ rank_members_in_leaderboard
562
+
563
+ @leaderboard.expire_leaderboard_at((Time.now + 10).to_i)
564
+ @redis_connection.ttl(@leaderboard.leaderboard_name).tap do |ttl|
565
+ ttl.should be > 1
566
+ ttl.should be <= 10
567
+ end
568
+ end
569
+
549
570
  it 'should allow you to rank multiple members with a variable number of arguments' do
550
571
  @leaderboard.total_members.should be(0)
551
572
  @leaderboard.rank_members('member_1', 1, 'member_10', 10)
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Leaderboard::VERSION' do
4
4
  it 'should be the correct version' do
5
- Leaderboard::VERSION.should == '2.2.1'
5
+ Leaderboard::VERSION.should == '2.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leaderboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-18 00:00:00.000000000 Z
12
+ date: 2012-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
97
  version: '0'
98
98
  segments:
99
99
  - 0
100
- hash: -27523170013791394
100
+ hash: -401137284638736499
101
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  none: false
103
103
  requirements:
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: -27523170013791394
109
+ hash: -401137284638736499
110
110
  requirements: []
111
111
  rubyforge_project: leaderboard
112
112
  rubygems_version: 1.8.23