leaderboard 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## leaderboard 2.4.0 (2012-07-30)
4
+
5
+ * Added `all_leaders` and `all_leaders_from` methods to retreive all members from a leaderboard. You may also use the aliases `all_members` or `all_members_from`.
6
+
3
7
  ## leaderboard 2.3.0 (2012-07-09)
4
8
 
5
9
  * Added `expire_leaderboard(seconds)` to expire the leaderboard in a set number of seconds.
data/README.markdown CHANGED
@@ -176,6 +176,9 @@ Below is an example of retrieving the first page in the leaderboard without scor
176
176
 
177
177
  You can also use the `members` and `members_in` methods as aliases for the `leaders` and `leaders_in` methods.
178
178
 
179
+ There are also a few convenience methods to be able to retrieve all leaders from a given leaderboard. They are `all_leaders` and `all_leaders_from`. You
180
+ may also use the aliases `all_members` or `all_members_from`. Use any of these methods sparingly as all the information in the leaderboard will be returned.
181
+
179
182
  Add more members to your leaderboard:
180
183
 
181
184
  ```ruby
data/lib/leaderboard.rb CHANGED
@@ -576,6 +576,42 @@ class Leaderboard
576
576
 
577
577
  alias_method :members_in, :leaders_in
578
578
 
579
+ # Retrieve all leaders from the leaderboard.
580
+ #
581
+ # @param options [Hash] Options to be used when retrieving the leaders from the leaderboard.
582
+ #
583
+ # @return the leaders from the leaderboard.
584
+ def all_leaders(options = {})
585
+ all_leaders_from(@leaderboard_name, options)
586
+ end
587
+
588
+ alias_method :all_members, :all_leaders
589
+
590
+ # Retrieves all leaders from the named leaderboard.
591
+ #
592
+ # @param leaderboard_name [String] Name of the leaderboard.
593
+ # @param options [Hash] Options to be used when retrieving the leaders from the named leaderboard.
594
+ #
595
+ # @return the named leaderboard.
596
+ def all_leaders_from(leaderboard_name, options = {})
597
+ leaderboard_options = DEFAULT_LEADERBOARD_REQUEST_OPTIONS.dup
598
+ leaderboard_options.merge!(options)
599
+
600
+ if @reverse
601
+ raw_leader_data = @redis_connection.zrange(leaderboard_name, 0, -1, :with_scores => false)
602
+ else
603
+ raw_leader_data = @redis_connection.zrevrange(leaderboard_name, 0, -1, :with_scores => false)
604
+ end
605
+
606
+ if raw_leader_data
607
+ return ranked_in_list_in(leaderboard_name, raw_leader_data, leaderboard_options)
608
+ else
609
+ return []
610
+ end
611
+ end
612
+
613
+ alias_method :all_members_from, :all_leaders_from
614
+
579
615
  # Retrieve members from the leaderboard within a given score range.
580
616
  #
581
617
  # @param minimum_score [float] Minimum score (inclusive).
@@ -1,4 +1,4 @@
1
1
  class Leaderboard
2
2
  # Leaderboard version
3
- VERSION = '2.3.0'.freeze
3
+ VERSION = '2.4.0'.freeze
4
4
  end
@@ -141,6 +141,22 @@ describe 'Leaderboard' do
141
141
  leaders.size.should be(1)
142
142
  end
143
143
 
144
+ %w(members leaders).each do |method|
145
+ it "should return the entire leaderboard when you call 'all_#{method}'" do
146
+ rank_members_in_leaderboard(27)
147
+
148
+ @leaderboard.total_members.should be(27)
149
+
150
+ members = @leaderboard.send("all_#{method}")
151
+
152
+ members.size.should be(27)
153
+ members[0][:member].should == 'member_27'
154
+ members[-2][:member].should == 'member_2'
155
+ members[-1][:member].should == 'member_1'
156
+ members[-1][:score].to_i.should be(1)
157
+ end
158
+ end
159
+
144
160
  it 'should allow you to retrieve members in a given score range' do
145
161
  rank_members_in_leaderboard(Leaderboard::DEFAULT_PAGE_SIZE)
146
162
 
data/spec/version_spec.rb CHANGED
@@ -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.3.0'
5
+ Leaderboard::VERSION.should == '2.4.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.3.0
4
+ version: 2.4.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-07-09 00:00:00.000000000 Z
12
+ date: 2012-07-30 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: -401137284638736499
100
+ hash: -2580404106533235495
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: -401137284638736499
109
+ hash: -2580404106533235495
110
110
  requirements: []
111
111
  rubyforge_project: leaderboard
112
112
  rubygems_version: 1.8.23