redness 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,13 +23,17 @@ class RedSet
23
23
  end
24
24
  end
25
25
  end
26
-
27
26
  ensure
28
27
  redis.execute_with_uncertainty(0) do
29
28
  redis.unwatch
30
29
  end
31
30
  end
32
31
 
32
+ def self.cap(key, size)
33
+ redis.execute_with_uncertainty(0) do
34
+ redis.zremrangebyrank(key, 0, -(size + 1))
35
+ end
36
+ end
33
37
 
34
38
  def self.remove(key, member)
35
39
  redis.execute_with_uncertainty do
@@ -1,4 +1,4 @@
1
1
  module Redness
2
- VERSION="0.1.5"
2
+ VERSION="0.1.6"
3
3
  MAJOR, MINOR, TINY = VERSION.split(".")
4
4
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.licenses = ["MIT"]
20
20
  s.files = `git ls-files`.split("\n")
21
21
  s.add_runtime_dependency "json"
22
- s.add_runtime_dependency "rspec"
22
+ s.add_development_dependency "rspec"
23
23
  s.add_runtime_dependency "redis", "~> 3.0.0"
24
24
  s.add_runtime_dependency "activesupport"
25
25
  s.add_development_dependency "timecop"
@@ -71,10 +71,44 @@ describe RedSet do
71
71
  set.should == [3,2]
72
72
  end
73
73
 
74
- it "sets the score when one is provided" do
75
- RedSet.add("somekey", 1, :score => lambda { 1000 })
74
+ context "when the score responds to #call" do
75
+ it "sets the score when one is provided" do
76
+ RedSet.add("somekey", 1, :score => lambda { 1000 })
76
77
 
77
- RedSet.score("somekey", 1).should == 1000
78
+ RedSet.score("somekey", 1).should == 1000
79
+ end
80
+ end
81
+
82
+ context "the score is anything else" do
83
+ it "sets the score when one is provided" do
84
+ RedSet.add("somekey", 1, score: 20)
85
+
86
+ RedSet.score("somekey", 1).should == 20
87
+ end
88
+ end
89
+ end
90
+
91
+ describe ".cap" do
92
+ it "caps the set at the given size, dropping earlier elements" do
93
+ RedSet.add('key', 4)
94
+ RedSet.add('key', 1)
95
+ RedSet.add('key', 3)
96
+ RedSet.add('key', 2)
97
+
98
+ RedSet.cap('key', 2)
99
+
100
+ RedSet.get('key').to_set.should == Set[2, 3]
101
+ end
102
+
103
+ it "does nothing if the set is smaller than the given size" do
104
+ RedSet.add('key', 1)
105
+ RedSet.cap('key', 2)
106
+ RedSet.get('key').should == [1]
107
+ end
108
+
109
+ it "does nothing if the set does not exist" do
110
+ RedSet.cap('key', 2)
111
+ RedSet.get('key').should == []
78
112
  end
79
113
  end
80
114
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,11 +14,11 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2012-10-25 00:00:00.000000000 Z
17
+ date: 2013-01-15 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: json
21
- requirement: &70238911257720 !ruby/object:Gem::Requirement
21
+ requirement: !ruby/object:Gem::Requirement
22
22
  none: false
23
23
  requirements:
24
24
  - - ! '>='
@@ -26,21 +26,31 @@ dependencies:
26
26
  version: '0'
27
27
  type: :runtime
28
28
  prerelease: false
29
- version_requirements: *70238911257720
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
30
35
  - !ruby/object:Gem::Dependency
31
36
  name: rspec
32
- requirement: &70238911276400 !ruby/object:Gem::Requirement
37
+ requirement: !ruby/object:Gem::Requirement
33
38
  none: false
34
39
  requirements:
35
40
  - - ! '>='
36
41
  - !ruby/object:Gem::Version
37
42
  version: '0'
38
- type: :runtime
43
+ type: :development
39
44
  prerelease: false
40
- version_requirements: *70238911276400
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
41
51
  - !ruby/object:Gem::Dependency
42
52
  name: redis
43
- requirement: &70238911275520 !ruby/object:Gem::Requirement
53
+ requirement: !ruby/object:Gem::Requirement
44
54
  none: false
45
55
  requirements:
46
56
  - - ~>
@@ -48,10 +58,15 @@ dependencies:
48
58
  version: 3.0.0
49
59
  type: :runtime
50
60
  prerelease: false
51
- version_requirements: *70238911275520
61
+ version_requirements: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 3.0.0
52
67
  - !ruby/object:Gem::Dependency
53
68
  name: activesupport
54
- requirement: &70238911275060 !ruby/object:Gem::Requirement
69
+ requirement: !ruby/object:Gem::Requirement
55
70
  none: false
56
71
  requirements:
57
72
  - - ! '>='
@@ -59,10 +74,15 @@ dependencies:
59
74
  version: '0'
60
75
  type: :runtime
61
76
  prerelease: false
62
- version_requirements: *70238911275060
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
63
83
  - !ruby/object:Gem::Dependency
64
84
  name: timecop
65
- requirement: &70238911274600 !ruby/object:Gem::Requirement
85
+ requirement: !ruby/object:Gem::Requirement
66
86
  none: false
67
87
  requirements:
68
88
  - - ! '>='
@@ -70,10 +90,15 @@ dependencies:
70
90
  version: '0'
71
91
  type: :development
72
92
  prerelease: false
73
- version_requirements: *70238911274600
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
74
99
  - !ruby/object:Gem::Dependency
75
100
  name: rake
76
- requirement: &70238911274000 !ruby/object:Gem::Requirement
101
+ requirement: !ruby/object:Gem::Requirement
77
102
  none: false
78
103
  requirements:
79
104
  - - ! '>='
@@ -81,7 +106,12 @@ dependencies:
81
106
  version: '0'
82
107
  type: :development
83
108
  prerelease: false
84
- version_requirements: *70238911274000
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
85
115
  description: Helpful Ruby classes for improved Redis data structures
86
116
  email: dev@howaboutwe.com
87
117
  executables: []
@@ -89,7 +119,6 @@ extensions: []
89
119
  extra_rdoc_files: []
90
120
  files:
91
121
  - .gitignore
92
- - .rspec
93
122
  - Gemfile
94
123
  - LICENSE.txt
95
124
  - RAKEFILE
@@ -142,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
171
  version: '0'
143
172
  requirements: []
144
173
  rubyforge_project:
145
- rubygems_version: 1.8.15
174
+ rubygems_version: 1.8.23
146
175
  signing_key:
147
176
  specification_version: 3
148
177
  summary: Helpful Ruby classes for improved Redis data structures
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color