Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for customization of member_data namespace #45

Merged
merged 1 commit into from
Feb 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ DEFAULT_OPTIONS = {
:member_key => :member,
:rank_key => :rank,
:score_key => :score,
:member_data_key => :member_data
:member_data_key => :member_data,
:member_data_namespace => 'member_data'
}
```

Expand Down
6 changes: 4 additions & 2 deletions lib/leaderboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Leaderboard
:member_key => :member,
:rank_key => :rank,
:score_key => :score,
:member_data_key => :member_data
:member_data_key => :member_data,
:member_data_namespace => 'member_data'
}

# Default Redis host: localhost
Expand Down Expand Up @@ -78,6 +79,7 @@ def initialize(leaderboard_name, options = DEFAULT_OPTIONS, redis_options = DEFA
@rank_key = leaderboard_options[:rank_key]
@score_key = leaderboard_options[:score_key]
@member_data_key = leaderboard_options[:member_data_key]
@member_data_namespace = leaderboard_options[:member_data_namespace]

@redis_connection = redis_options[:redis_connection]
unless @redis_connection.nil?
Expand Down Expand Up @@ -972,7 +974,7 @@ def intersect_leaderboards(destination, keys, options = {:aggregate => :sum})
#
# @return a key in the form of +leaderboard_name:member_data+
def member_data_key(leaderboard_name)
"#{leaderboard_name}:member_data"
"#{leaderboard_name}:#{@member_data_namespace}"
end

# Validate and return the page size. Returns the +DEFAULT_PAGE_SIZE+ if the page size is less than 1.
Expand Down
8 changes: 8 additions & 0 deletions spec/leaderboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,12 @@
leader[:member_data].should be_nil
end
end

it 'should allow you to change the :member_data_namespace option' do
@leaderboard = Leaderboard.new('name', {:member_data_namespace => 'md'}, {:host => "127.0.0.1", :db => 15})
rank_members_in_leaderboard

@redis_connection.exists("name:member_data").should be_false
@redis_connection.exists("name:md").should be_true
end
end