silver_spoon 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --format nested
3
+ --order random
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.0.1
3
+ ## 0.0.2
4
+
5
+ * Fixed bug in has_entitlements?. I'm not sure how it was ever correct :(
6
+
7
+ ## 0.0.1
4
8
 
5
9
  * Initial release
@@ -1,17 +1,39 @@
1
1
  module SilverSpoon
2
2
  module Entitlements
3
+ # Add an entitlement for a given +id+.
4
+ #
5
+ # @param id [String] Identifier.
6
+ # @param entitlement_key [String] Entitlement key.
7
+ # @param entitlement_value [String] Entitlement value.
8
+ # @param scope [String, SilverSpoon.default_scope] Scope.
3
9
  def add_entitlement(id, entitlement_key, entitlement_value, scope = SilverSpoon.default_scope)
4
10
  add_entitlements(id, [entitlement_key], [entitlement_value], scope)
5
11
  end
6
12
 
13
+ # Add multiple entitlements for a given +id+.
14
+ #
15
+ # @param id [String] Identifier.
16
+ # @param entitlement_keys [Array of String] Entitlement keys.
17
+ # @param entitlement_values [Array of String] Entilement values.
18
+ # @param scope [String, SilverSpoon.default_scope] Scope.
7
19
  def add_entitlements(id, entitlement_keys, entitlement_values, scope = SilverSpoon.default_scope)
8
20
  SilverSpoon.redis.hmset(silver_spoon_key(id, SilverSpoon.namespace, scope), *entitlement_keys.zip(entitlement_values).flatten!)
9
21
  end
10
22
 
23
+ # Remove an entitlement for a given +id+.
24
+ #
25
+ # @param id [String] Identifier.
26
+ # @param entitlement_key [String] Entitlement key.
27
+ # @param scope [String, SilverSpoon.default_scope] Scope.
11
28
  def remove_entitlement(id, entitlement_key, scope = SilverSpoon.default_scope)
12
29
  remove_entitlements(id, [entitlement_key], scope)
13
30
  end
14
31
 
32
+ # Remove multiple entitlements for a given +id+.
33
+ #
34
+ # @param id [String] Identifier.
35
+ # @param entitlement_keys [Array of String] Entitlement keys.
36
+ # @param scope [String, SilverSpoon.default_scope] Scope.
15
37
  def remove_entitlements(id, entitlement_keys, scope = SilverSpoon.default_scope)
16
38
  SilverSpoon.redis.multi do |transaction|
17
39
  entitlement_keys.each do |entitlement_key|
@@ -20,28 +42,63 @@ module SilverSpoon
20
42
  end
21
43
  end
22
44
 
45
+ # Retrieve an entitlement for a given +id+.
46
+ #
47
+ # @param id [String] Identifier.
48
+ # @param entitlement_key [String] Entitlement key.
49
+ # @param scope [String, SilverSpoon.default_scope] Scope.
50
+ #
51
+ # @return Hash of entitlement key to entitlement value.
23
52
  def retrieve_entitlement(id, entitlement_key, scope = SilverSpoon.default_scope)
24
53
  retrieve_entitlements(id, [entitlement_key], scope)
25
54
  end
26
55
 
56
+ # Retrieve a set of entitlements for a given +id+.
57
+ #
58
+ # @param id [String] Identifier.
59
+ # @param entitlement_keys [Array of String] Entitlement keys.
60
+ # @param scope [String, SilverSpoon.default_scope] Scope.
61
+ #
62
+ # @return Hash of entitlement keys to entitlement values.
27
63
  def retrieve_entitlements(id, entitlement_keys, scope = SilverSpoon.default_scope)
28
64
  Hash[*entitlement_keys.zip(SilverSpoon.redis.hmget(silver_spoon_key(id, SilverSpoon.namespace, scope), *entitlement_keys)).flatten!]
29
65
  end
30
66
 
67
+ # Check to see if a given +id+ has a given entitlement.
68
+ #
69
+ # @param id [String] Identifier.
70
+ # @param entitlement_key [String] Entitlement key.
71
+ # @param scope [String, SilverSpoon.default_scope] Scope.
72
+ #
73
+ # @return +true+ if the +id+ has the requested entitlement, +false+ otherwise.
31
74
  def has_entitlement?(id, entitlement_key, scope = SilverSpoon.default_scope)
32
75
  SilverSpoon.redis.hexists(silver_spoon_key(id, SilverSpoon.namespace, scope), entitlement_key)
33
76
  end
34
77
 
78
+ # Check to see if a given +id+ has a given set of entitlements.
79
+ #
80
+ # @param id [String] Identifier.
81
+ # @param entitlement_keys [Array of String] Entitlement keys.
82
+ # @param scope [String, SilverSpoon.default_scope] Scope.
83
+ #
84
+ # @return Array where +true+ if the +id+ has the requested entitlement, +false+ otherwise for each entitlement.
35
85
  def has_entitlements?(id, entitlement_keys, scope = SilverSpoon.default_scope)
36
86
  SilverSpoon.redis.multi do |transaction|
37
87
  entitlement_keys.each do |entitlement_key|
38
88
  transaction.hexists(silver_spoon_key(id, SilverSpoon.namespace, scope), entitlement_key)
39
89
  end
40
- end.map { |value| value == 0 ? false : true }
90
+ end
41
91
  end
42
92
 
43
- private
93
+ private
44
94
 
95
+ # Helper method for SilverSpoon keys in form of +id:namespace:scope+.
96
+ #
97
+ # @param id [String] Identifier.
98
+ # @param namespace [String] Namespace.
99
+ # @param scope [String] Scope.
100
+ #
101
+ # @return Key in form of +id:namespace:scope+.
45
102
  def silver_spoon_key(id, namespace, scope)
46
103
  "#{namespace}:#{scope}:#{id}"
47
104
  end
@@ -1,3 +1,3 @@
1
1
  module SilverSpoon
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'SilverSpoon::VERSION' do
4
4
  it 'should be the correct version' do
5
- SilverSpoon::VERSION.should == '0.0.1'
5
+ SilverSpoon::VERSION.should == '0.0.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: silver_spoon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-04-27 00:00:00.000000000 Z
12
+ date: 2012-09-24 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: 3943121066716164985
100
+ hash: -3056986767722262899
101
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  none: false
103
103
  requirements:
@@ -106,10 +106,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: 3943121066716164985
109
+ hash: -3056986767722262899
110
110
  requirements: []
111
111
  rubyforge_project:
112
- rubygems_version: 1.8.23
112
+ rubygems_version: 1.8.24
113
113
  signing_key:
114
114
  specification_version: 3
115
115
  summary: Entitlements in Redis. A simple wrapper around Redis hashes for adding, removing,