ohm-sorted 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +4 -0
- data/lib/ohm/sorted.rb +7 -2
- data/ohm-sorted.gemspec +1 -1
- data/test/sorted_test.rb +15 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODM0YjY5ZGI2ZjdiNjk4Mjc0OGZkNTEwNjZlOTQ3NzcwYTRkNWI3NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDNmZTcwMWNmNjBkNmExODdkMDc0MWFlM2M1NjAyZGZmZWI5YWRlMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDRiYzFhMzQ0N2YzODI5N2JkMDczOWNlN2QxNGQxNDRiMDgwYWRhYTY5YTFj
|
10
|
+
OWI3NmU2MzljYzFlNzZkYWVhYmZlOTYzN2I1ODQ2Y2I3NTE2YWViZmEzMmIy
|
11
|
+
YWRhYzliYzZmMTVmZjQyYmVmMGM2OWE5ZWU0NGVkMmIwODNmZDc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzA4ZWNmOTM3OGU1OGUxOTY4NTcxYjZlNmU2ODI5NGZiMmJlOTRmZDI1ZDBj
|
14
|
+
YzM3MjViZWIyZDA4ZDc3MTQ3MDVjOTcwNTZkMjNhYTUzODIwYzkwYWJlNTcy
|
15
|
+
MjJhYTFlMWUzMjBiOGU3OTgxMjY1ODdkN2E1ZTQzMzEyNmRlZjM=
|
data/CHANGELOG.md
CHANGED
data/lib/ohm/sorted.rb
CHANGED
@@ -30,7 +30,7 @@ module Ohm
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def size
|
33
|
-
execute { |key| db.zcard(key) }
|
33
|
+
execute { |key| fix_size(db.zcard(key)) }
|
34
34
|
end
|
35
35
|
|
36
36
|
def between(first, last)
|
@@ -78,6 +78,11 @@ module Ohm
|
|
78
78
|
def inspect
|
79
79
|
"#<SortedSet (#{model}): #{ids}>"
|
80
80
|
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def fix_size(value)
|
84
|
+
[[value - offset, 0].max, count >= 0 ? count : Float::INFINITY].min
|
85
|
+
end
|
81
86
|
end
|
82
87
|
|
83
88
|
if defined?(BasicSet)
|
@@ -135,7 +140,7 @@ module Ohm
|
|
135
140
|
|
136
141
|
class RangedSortedSet < SortedSet
|
137
142
|
def size
|
138
|
-
execute { |key| db.zcount(key, @range.first, @range.last) }
|
143
|
+
execute { |key| fix_size(db.zcount(key, @range.first, @range.last)) }
|
139
144
|
end
|
140
145
|
end
|
141
146
|
|
data/ohm-sorted.gemspec
CHANGED
data/test/sorted_test.rb
CHANGED
@@ -149,6 +149,21 @@ class SortedTest < Test::Unit::TestCase
|
|
149
149
|
assert_equal 2, sorted_set.size
|
150
150
|
end
|
151
151
|
|
152
|
+
def test_sorted_set_sliced_size
|
153
|
+
4.times do |i|
|
154
|
+
Post.create(order: i)
|
155
|
+
end
|
156
|
+
|
157
|
+
sorted_set = Post.sorted_find(:order).slice(2, 10)
|
158
|
+
assert_equal 2, sorted_set.size
|
159
|
+
|
160
|
+
sorted_set = Post.sorted_find(:order).slice(4, 1)
|
161
|
+
assert_equal 0, sorted_set.size
|
162
|
+
|
163
|
+
sorted_set = Post.sorted_find(:order).slice(1, 1)
|
164
|
+
assert_equal 1, sorted_set.size
|
165
|
+
end
|
166
|
+
|
152
167
|
def test_sorted_set_empty
|
153
168
|
sorted_set = Post.sorted_find(:order)
|
154
169
|
assert sorted_set.empty?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohm-sorted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Bond
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.1
|
93
|
+
rubygems_version: 2.2.1
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: Sorted indices for Ohm.
|