rufus-cloche 0.1.18 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,13 @@
2
2
  = rufus-cloche CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-cloche - 0.1.19 not yet released
6
+
7
+ - get_many(type, regexes) where regexes might be strings (end of key) or Regexp
8
+ instances
9
+ - get_many(type, regex, :count => true) bug fix (when empty)
10
+
11
+
5
12
  == rufus-cloche - 0.1.18 released 2010/08/05
6
13
 
7
14
  - get_many(type, regex, :count => true)
data/lib/rufus/cloche.rb CHANGED
@@ -43,7 +43,7 @@ module Rufus
43
43
  #
44
44
  class Cloche
45
45
 
46
- VERSION = '0.1.18'
46
+ VERSION = '0.1.19'
47
47
 
48
48
  WIN = (RUBY_PLATFORM.match(/mswin|mingw/) != nil)
49
49
 
@@ -177,13 +177,15 @@ module Rufus
177
177
  # If :count => true, the query will simply return the number of documents
178
178
  # that matched.
179
179
  #
180
- def get_many (type, key_match=nil, opts={})
180
+ def get_many (type, regex=nil, opts={})
181
181
 
182
182
  opts = opts.inject({}) { |h, (k, v)| h[k.to_s] = v; h }
183
183
 
184
184
  d = dir_for(type)
185
185
 
186
- return [] unless File.exist?(d)
186
+ return (opts['count'] ? 0 : []) unless File.exist?(d)
187
+
188
+ regexes = regex ? Array(regex) : nil
187
189
 
188
190
  docs = []
189
191
  skipped = 0
@@ -200,7 +202,7 @@ module Rufus
200
202
 
201
203
  key = File.basename(fn, '.json')
202
204
 
203
- if (not key_match) or key.match(key_match)
205
+ if regexes.nil? or match?(key, regexes)
204
206
 
205
207
  skipped = skipped + 1
206
208
  next if skip and skipped <= skip
@@ -260,6 +262,13 @@ module Rufus
260
262
 
261
263
  protected
262
264
 
265
+ def match? (key, regexes)
266
+
267
+ regexes.first.is_a?(Regexp) ?
268
+ regexes.find { |regex| regex.match(key) } :
269
+ regexes.find { |s| key[-s.length..-1] == s }
270
+ end
271
+
263
272
  def self.neutralize (s)
264
273
 
265
274
  s.to_s.strip.gsub(/[ \/:;\*\\\+\?]/, '_')
data/rufus-cloche.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rufus-cloche}
8
- s.version = "0.1.18"
8
+ s.version = "0.1.19"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Mettraux"]
12
- s.date = %q{2010-08-05}
12
+ s.date = %q{2010-08-09}
13
13
  s.description = %q{
14
14
  A very stupid JSON hash store.
15
15
 
data/test/test.rb CHANGED
@@ -158,6 +158,7 @@ class ClocheTest < Test::Unit::TestCase
158
158
  load_people
159
159
 
160
160
  assert_equal 2, @c.get_many('person', /^j/).size
161
+ assert_equal 2, @c.get_many('person', 'o').size
161
162
  end
162
163
 
163
164
  def test_get_many_key_order
@@ -200,6 +201,15 @@ class ClocheTest < Test::Unit::TestCase
200
201
  assert_equal %w[ chicko-chan ], @c.real_ids('animal')
201
202
  end
202
203
 
204
+ def test_get_many_count
205
+
206
+ assert_equal(0, @c.get_many('person', nil, :count => true))
207
+
208
+ load_people
209
+
210
+ assert_equal(4, @c.get_many('person', nil, :count => true))
211
+ end
212
+
203
213
  def test_get_many_options
204
214
 
205
215
  load_people
@@ -215,6 +225,17 @@ class ClocheTest < Test::Unit::TestCase
215
225
  assert_equal(2, @c.get_many('person', /^j/, :count => true))
216
226
  end
217
227
 
228
+ # it's not necessary to differentiate select_id and select_doc ...
229
+
230
+ def test_get_many_keys
231
+
232
+ load_people
233
+
234
+ assert_equal(
235
+ %w[ jami john ],
236
+ @c.get_many('person', [ /jami/, /john/ ]).collect { |d| d['_id'] })
237
+ end
238
+
218
239
  protected
219
240
 
220
241
  def load_people
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 18
9
- version: 0.1.18
8
+ - 19
9
+ version: 0.1.19
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Mettraux
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-05 00:00:00 +09:00
17
+ date: 2010-08-09 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency