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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2ViM2QyN2RiM2MxZjlkMmQzZmNiYjU5NTg3MDZiMDdiYmI2YWQyOA==
4
+ ODM0YjY5ZGI2ZjdiNjk4Mjc0OGZkNTEwNjZlOTQ3NzcwYTRkNWI3NQ==
5
5
  data.tar.gz: !binary |-
6
- MDQ3NTcwYTIwYmQzN2I4NDNiYjg4ODRjNmY3Y2NiNGQzMDI0NGU3MA==
6
+ MDNmZTcwMWNmNjBkNmExODdkMDc0MWFlM2M1NjAyZGZmZWI5YWRlMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWQ5N2FkODJhMjU2MGRlZDRhMGQxNWJiZmJjYmZmMmU1NjU1NWU4YmVkZWIw
10
- OTkxMjU1NDZjMThkZWU1NTIwYjE1YzVlYzBkNmJiYWE5M2JjMTM2YzRlNTAz
11
- MGI0ZjVlYjY5NzM4NjMyYjJiNjg4YjM4ZTg4YjNjMDlkZGNlN2E=
9
+ NDRiYzFhMzQ0N2YzODI5N2JkMDczOWNlN2QxNGQxNDRiMDgwYWRhYTY5YTFj
10
+ OWI3NmU2MzljYzFlNzZkYWVhYmZlOTYzN2I1ODQ2Y2I3NTE2YWViZmEzMmIy
11
+ YWRhYzliYzZmMTVmZjQyYmVmMGM2OWE5ZWU0NGVkMmIwODNmZDc=
12
12
  data.tar.gz: !binary |-
13
- NDUyMzI2YmZiYmUwYTZmNmNjYTJjNjliZTlmYTBhYzhlODY3YWYxOTM2MmEw
14
- MDUyN2ViMjE1MTZkNmNkOThlNjQwZDJjYmI3Y2MzOGEzMGQzMWI5YjZiMTE4
15
- YTI2ZDZkZmQ0MDgxMGE2NzI5NjVhYjkzNWM4ZmEyOGFjZDY4NmM=
13
+ YzA4ZWNmOTM3OGU1OGUxOTY4NTcxYjZlNmU2ODI5NGZiMmJlOTRmZDI1ZDBj
14
+ YzM3MjViZWIyZDA4ZDc3MTQ3MDVjOTcwNTZkMjNhYTUzODIwYzkwYWJlNTcy
15
+ MjJhYTFlMWUzMjBiOGU3OTgxMjY1ODdkN2E1ZTQzMzEyNmRlZjM=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.3.4
2
+
3
+ - Fix `SortedSet#size` when using slicing
4
+
1
5
  ### 0.3.3
2
6
 
3
7
  - Fix broken `SortedSet#each` behavior
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ohm-sorted'
3
- s.version = '0.3.3'
3
+ s.version = '0.3.4'
4
4
  s.summary = "Sorted indices for Ohm."
5
5
  s.description = "An plugin for Ohm that lets you create sorted indices."
6
6
  s.author = "Federico Bond"
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.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: 2013-10-08 00:00:00.000000000 Z
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.5
93
+ rubygems_version: 2.2.1
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: Sorted indices for Ohm.