silver_spoon 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +111 -0
- data/Rakefile +12 -0
- data/lib/silver_spoon/configuration.rb +39 -0
- data/lib/silver_spoon/entitlements.rb +49 -0
- data/lib/silver_spoon/version.rb +3 -0
- data/lib/silver_spoon.rb +9 -0
- data/silver_spoon.gemspec +21 -0
- data/spec/silver_spoon/configuration_spec.rb +12 -0
- data/spec/silver_spoon/entitlements_spec.rb +131 -0
- data/spec/silver_spoon/version_spec.rb +7 -0
- data/spec/spec_helper.rb +22 -0
- metadata +121 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3@silver_spoon_gem --create
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 David Czarnecki
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# SilverSpoon
|
2
|
+
|
3
|
+
Entitlements in Redis. A simple semantic wrapper around Redis hashes for adding, removing, retrieving and
|
4
|
+
checking existence of entitlements.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```
|
11
|
+
gem 'silver_spoon'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
```
|
17
|
+
$ bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
```
|
23
|
+
$ gem install silver_spoon
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Configuration:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
SilverSpoon.configure do |configuration|
|
32
|
+
configuration.redis = Redis.new
|
33
|
+
configuration.namespace = 'silver_spoon'
|
34
|
+
configuration.default_scope = 'entitlements'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
The hash key used in looking up entitlements for a given `id` is as follows:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
"#{SilverSpoon.namespace}:#{scope}:#{id}"
|
42
|
+
```
|
43
|
+
|
44
|
+
You can use the `scope` property in the various calls to retrieve entitlement data
|
45
|
+
in another context. This may be useful if you want to allow, for example, entitlements
|
46
|
+
for multiple games or different membership products.
|
47
|
+
|
48
|
+
Adding entitlements:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
add_entitlement(id, entitlement_key, entitlement_value, scope = SilverSpoon.default_scope)
|
52
|
+
add_entitlements(id, entitlement_keys, entitlement_values, scope = SilverSpoon.default_scope)
|
53
|
+
```
|
54
|
+
|
55
|
+
Removing entitlements:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
remove_entitlement(id, entitlement_key, scope = SilverSpoon.default_scope)
|
59
|
+
remove_entitlements(id, entitlement_keys, scope = SilverSpoon.default_scope)
|
60
|
+
```
|
61
|
+
|
62
|
+
Checking entitlements:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
has_entitlement?(id, entitlement_key, scope = SilverSpoon.default_scope)
|
66
|
+
has_entitlements?(id, entitlement_keys, scope = SilverSpoon.default_scope)
|
67
|
+
```
|
68
|
+
|
69
|
+
Retrieving entitlements:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
retrieve_entitlement(id, entitlement_key, scope = SilverSpoon.default_scope)
|
73
|
+
retrieve_entitlements(id, entitlement_keys, scope = SilverSpoon.default_scope)
|
74
|
+
```
|
75
|
+
|
76
|
+
Complete example:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
require 'silver_spoon'
|
80
|
+
=> true
|
81
|
+
SilverSpoon.configure do |configuration|
|
82
|
+
configuration.redis = Redis.new
|
83
|
+
configuration.namespace = 'silver_spoon'
|
84
|
+
configuration.default_scope = 'entitlements'
|
85
|
+
end
|
86
|
+
=> "entitlements"
|
87
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement')
|
88
|
+
=> false
|
89
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value')
|
90
|
+
=> "OK"
|
91
|
+
SilverSpoon.add_entitlement('david', 'another_entitlement', 'another_entitlement_value')
|
92
|
+
=> "OK"
|
93
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement'])
|
94
|
+
=> [true, true]
|
95
|
+
SilverSpoon.has_entitlement?('david', 'unknown_entitlement')
|
96
|
+
=> false
|
97
|
+
SilverSpoon.retrieve_entitlements('david', ['an_entitlement', 'another_entitlement'])
|
98
|
+
=> {"an_entitlement"=>"an_entitlement_value", "another_entitlement"=>"another_entitlement_value"}
|
99
|
+
```
|
100
|
+
|
101
|
+
## Contributing
|
102
|
+
|
103
|
+
1. Fork it
|
104
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
105
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
106
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
107
|
+
5. Create new Pull Request
|
108
|
+
|
109
|
+
## Copyright
|
110
|
+
|
111
|
+
Copyright (c) 2012 David Czarnecki. See LICENSE for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rake'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
7
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
8
|
+
spec.rspec_opts = ['--backtrace']
|
9
|
+
# spec.ruby_opts = ['-w']
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :spec
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SilverSpoon
|
2
|
+
module Configuration
|
3
|
+
# Redis instance.
|
4
|
+
attr_accessor :redis
|
5
|
+
|
6
|
+
# silver_spoon namespace for Redis.
|
7
|
+
attr_writer :namespace
|
8
|
+
|
9
|
+
# Default scope for entitlements.
|
10
|
+
attr_writer :default_scope
|
11
|
+
|
12
|
+
# Yield self to be able to configure silver_spoon with block-style configuration.
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
#
|
16
|
+
# SilverSpoon.configure do |configuration|
|
17
|
+
# configuration.redis = Redis.new
|
18
|
+
# configuration.namespace = 'silver_spoon'
|
19
|
+
# configuration.default_scope = 'entitlements'
|
20
|
+
# end
|
21
|
+
def configure
|
22
|
+
yield self
|
23
|
+
end
|
24
|
+
|
25
|
+
# silver_spoon namespace for Redis.
|
26
|
+
#
|
27
|
+
# @return the silver_spoon namespace or the default of 'silver_spoon' if not set.
|
28
|
+
def namespace
|
29
|
+
@namespace ||= 'silver_spoon'
|
30
|
+
end
|
31
|
+
|
32
|
+
# Default scope for entitlements.
|
33
|
+
#
|
34
|
+
# @return the default scope for entitlements or the default of 'entitlements' if not set.
|
35
|
+
def default_scope
|
36
|
+
@default_scope ||= 'entitlements'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module SilverSpoon
|
2
|
+
module Entitlements
|
3
|
+
def add_entitlement(id, entitlement_key, entitlement_value, scope = SilverSpoon.default_scope)
|
4
|
+
add_entitlements(id, [entitlement_key], [entitlement_value], scope)
|
5
|
+
end
|
6
|
+
|
7
|
+
def add_entitlements(id, entitlement_keys, entitlement_values, scope = SilverSpoon.default_scope)
|
8
|
+
SilverSpoon.redis.hmset(silver_spoon_key(id, SilverSpoon.namespace, scope), *entitlement_keys.zip(entitlement_values).flatten!)
|
9
|
+
end
|
10
|
+
|
11
|
+
def remove_entitlement(id, entitlement_key, scope = SilverSpoon.default_scope)
|
12
|
+
remove_entitlements(id, [entitlement_key], scope)
|
13
|
+
end
|
14
|
+
|
15
|
+
def remove_entitlements(id, entitlement_keys, scope = SilverSpoon.default_scope)
|
16
|
+
SilverSpoon.redis.multi do |transaction|
|
17
|
+
entitlement_keys.each do |entitlement_key|
|
18
|
+
transaction.hdel(silver_spoon_key(id, SilverSpoon.namespace, scope), entitlement_key)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def retrieve_entitlement(id, entitlement_key, scope = SilverSpoon.default_scope)
|
24
|
+
retrieve_entitlements(id, [entitlement_key], scope)
|
25
|
+
end
|
26
|
+
|
27
|
+
def retrieve_entitlements(id, entitlement_keys, scope = SilverSpoon.default_scope)
|
28
|
+
Hash[*entitlement_keys.zip(SilverSpoon.redis.hmget(silver_spoon_key(id, SilverSpoon.namespace, scope), *entitlement_keys)).flatten!]
|
29
|
+
end
|
30
|
+
|
31
|
+
def has_entitlement?(id, entitlement_key, scope = SilverSpoon.default_scope)
|
32
|
+
SilverSpoon.redis.hexists(silver_spoon_key(id, SilverSpoon.namespace, scope), entitlement_key)
|
33
|
+
end
|
34
|
+
|
35
|
+
def has_entitlements?(id, entitlement_keys, scope = SilverSpoon.default_scope)
|
36
|
+
SilverSpoon.redis.multi do |transaction|
|
37
|
+
entitlement_keys.each do |entitlement_key|
|
38
|
+
transaction.hexists(silver_spoon_key(id, SilverSpoon.namespace, scope), entitlement_key)
|
39
|
+
end
|
40
|
+
end.map { |value| value == 0 ? false : true }
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def silver_spoon_key(id, namespace, scope)
|
46
|
+
"#{namespace}:#{scope}:#{id}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/silver_spoon.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/silver_spoon/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["David Czarnecki"]
|
6
|
+
gem.email = ["dczarnecki@agoragames.com"]
|
7
|
+
gem.description = %q{Entitlements in Redis}
|
8
|
+
gem.summary = %q{Entitlements in Redis. A simple wrapper around Redis hashes for adding, removing, and checking existence of entitlements.}
|
9
|
+
gem.homepage = "https://github.com/agoragames/silver_spoon"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "silver_spoon"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = SilverSpoon::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'redis'
|
19
|
+
gem.add_development_dependency 'rake'
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SilverSpoon::Configuration do
|
4
|
+
describe '#configure' do
|
5
|
+
it 'should have default attributes' do
|
6
|
+
SilverSpoon.configure do |configuration|
|
7
|
+
configuration.namespace.should == 'silver_spoon'
|
8
|
+
configuration.default_scope.should == 'entitlements'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SilverSpoon::Entitlements do
|
4
|
+
describe '#add_entitlement ', '#has_entitlement?' do
|
5
|
+
it 'should set an entitlement if not already set for a given id, entitlement_key and default scope' do
|
6
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement').should be_false
|
7
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value')
|
8
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement').should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should set an entitlement if not already set for a given id, entitlement_key and given scope' do
|
12
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement').should be_false
|
13
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement', 'another_scope').should be_false
|
14
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value', 'another_scope')
|
15
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement').should be_false
|
16
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement', 'another_scope').should be_true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#add_entitlements' do
|
21
|
+
it 'should allow you to set multiple entitlements at once' do
|
22
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement']).should == [false, false]
|
23
|
+
SilverSpoon.add_entitlements('david', ['an_entitlement', 'another_entitlement'], ['an_entitlement_value', 'another_entitlement_value'])
|
24
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement']).should == [true, true]
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should allow you to set multiple entitlements at once for a given scope' do
|
28
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement']).should == [false, false]
|
29
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement'], 'another_scope').should == [false, false]
|
30
|
+
SilverSpoon.add_entitlements('david', ['an_entitlement', 'another_entitlement'], ['an_entitlement_value', 'another_entitlement_value'], 'another_scope')
|
31
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement']).should == [false, false]
|
32
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement'], 'another_scope').should == [true, true]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#remove_entitlement' do
|
37
|
+
it 'should remove an entitlement' do
|
38
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value')
|
39
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement').should be_true
|
40
|
+
SilverSpoon.remove_entitlement('david', 'an_entitlement')
|
41
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement').should be_false
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should remove an entitlement from a given scope' do
|
45
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value')
|
46
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value', 'another_scope')
|
47
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement').should be_true
|
48
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement', 'another_scope').should be_true
|
49
|
+
SilverSpoon.remove_entitlement('david', 'an_entitlement', 'another_scope')
|
50
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement').should be_true
|
51
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement', 'another_scope').should be_false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#remove_entitlements' do
|
56
|
+
it 'should allow you to remove multiple entitlements at once' do
|
57
|
+
SilverSpoon.add_entitlements('david', ['an_entitlement', 'another_entitlement'], ['an_entitlement_value', 'another_entitlement_value'])
|
58
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement']).should == [true, true]
|
59
|
+
SilverSpoon.remove_entitlements('david', ['an_entitlement', 'another_entitlement'])
|
60
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement']).should == [false, false]
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should allow you to remove multiple entitlements at once for a given scope' do
|
64
|
+
SilverSpoon.add_entitlements('david', ['an_entitlement', 'another_entitlement'], ['an_entitlement_value', 'another_entitlement_value'])
|
65
|
+
SilverSpoon.add_entitlements('david', ['an_entitlement', 'another_entitlement'], ['an_entitlement_value', 'another_entitlement_value'], 'another_scope')
|
66
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement']).should == [true, true]
|
67
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement'], 'another_scope').should == [true, true]
|
68
|
+
SilverSpoon.remove_entitlements('david', ['an_entitlement', 'another_entitlement'], 'another_scope')
|
69
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement']).should == [true, true]
|
70
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement'], 'another_scope').should == [false, false]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#retrieve_entitlement' do
|
75
|
+
it 'should retrieve an entitlement' do
|
76
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value')
|
77
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement').should be_true
|
78
|
+
SilverSpoon.retrieve_entitlement('david', 'an_entitlement').should == {'an_entitlement' => 'an_entitlement_value'}
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should retrieve an entitlement for a given scope' do
|
82
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value')
|
83
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'another_entitlement_value', 'another_scope')
|
84
|
+
SilverSpoon.has_entitlement?('david', 'an_entitlement').should be_true
|
85
|
+
SilverSpoon.retrieve_entitlement('david', 'an_entitlement', 'another_scope').should == {'an_entitlement' => 'another_entitlement_value'}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#retrieve_entitlements' do
|
90
|
+
it 'should retrieve multiple entitlements' do
|
91
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value')
|
92
|
+
SilverSpoon.add_entitlement('david', 'another_entitlement', 'another_entitlement_value')
|
93
|
+
SilverSpoon.retrieve_entitlements('david', ['an_entitlement', 'another_entitlement']).should ==
|
94
|
+
{
|
95
|
+
'an_entitlement' => 'an_entitlement_value',
|
96
|
+
'another_entitlement' => 'another_entitlement_value'
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should retrieve multiple entitlements for a given scope' do
|
101
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value')
|
102
|
+
SilverSpoon.add_entitlement('david', 'another_entitlement', 'another_entitlement_value')
|
103
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement2', 'an_entitlement_value', 'another_scope')
|
104
|
+
SilverSpoon.add_entitlement('david', 'another_entitlement2', 'another_entitlement_value', 'another_scope')
|
105
|
+
SilverSpoon.retrieve_entitlements('david', ['an_entitlement2', 'another_entitlement2', 'unknown_entitlement'], 'another_scope').should ==
|
106
|
+
{
|
107
|
+
'an_entitlement2' => 'an_entitlement_value',
|
108
|
+
'another_entitlement2' => 'another_entitlement_value',
|
109
|
+
'unknown_entitlement' => nil
|
110
|
+
}
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#has_entitlements?' do
|
115
|
+
it 'should allow you to check for multiple entitlements at once' do
|
116
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement']).should == [false, false]
|
117
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value')
|
118
|
+
SilverSpoon.add_entitlement('david', 'another_entitlement', 'another_entitlement_value')
|
119
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement', 'unknown_entitlement']).should == [true, true, false]
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should allow you to check for multiple entitlements at once for a given scope' do
|
123
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement']).should == [false, false]
|
124
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value')
|
125
|
+
SilverSpoon.add_entitlement('david', 'an_entitlement', 'an_entitlement_value', 'another_scope')
|
126
|
+
SilverSpoon.add_entitlement('david', 'another_entitlement', 'another_entitlement_value')
|
127
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement', 'unknown_entitlement']).should == [true, true, false]
|
128
|
+
SilverSpoon.has_entitlements?('david', ['an_entitlement', 'another_entitlement', 'unknown_entitlement'], 'another_scope').should == [true, false, false]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'silver_spoon'
|
3
|
+
|
4
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.before(:all) do
|
8
|
+
SilverSpoon.configure do |configuration|
|
9
|
+
redis = Redis.new(:db => 15)
|
10
|
+
configuration.redis = redis
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
config.before(:each) do
|
15
|
+
SilverSpoon.redis.flushdb
|
16
|
+
end
|
17
|
+
|
18
|
+
config.after(:all) do
|
19
|
+
SilverSpoon.redis.flushdb
|
20
|
+
SilverSpoon.redis.quit
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: silver_spoon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Czarnecki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redis
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Entitlements in Redis
|
63
|
+
email:
|
64
|
+
- dczarnecki@agoragames.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- .rvmrc
|
72
|
+
- CHANGELOG.md
|
73
|
+
- Gemfile
|
74
|
+
- LICENSE
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- lib/silver_spoon.rb
|
78
|
+
- lib/silver_spoon/configuration.rb
|
79
|
+
- lib/silver_spoon/entitlements.rb
|
80
|
+
- lib/silver_spoon/version.rb
|
81
|
+
- silver_spoon.gemspec
|
82
|
+
- spec/silver_spoon/configuration_spec.rb
|
83
|
+
- spec/silver_spoon/entitlements_spec.rb
|
84
|
+
- spec/silver_spoon/version_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
homepage: https://github.com/agoragames/silver_spoon
|
87
|
+
licenses: []
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: 3943121066716164985
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: 3943121066716164985
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.8.23
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Entitlements in Redis. A simple wrapper around Redis hashes for adding, removing,
|
116
|
+
and checking existence of entitlements.
|
117
|
+
test_files:
|
118
|
+
- spec/silver_spoon/configuration_spec.rb
|
119
|
+
- spec/silver_spoon/entitlements_spec.rb
|
120
|
+
- spec/silver_spoon/version_spec.rb
|
121
|
+
- spec/spec_helper.rb
|