groovy 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0c1e884b501a549852378578a4dfd5b6f276b43261536c3af41fe6701b73fb8
4
- data.tar.gz: 0b97dc5daad7e8ceb61477d496792372b358126be3385f69a2a8e7996b0ff789
3
+ metadata.gz: 110e7b285ae629862ff897e7069044bceff9c104b5b237fa8268ac692f493639
4
+ data.tar.gz: b4d4058f54bb63ab377c8d985802893f8cba1b7a9941def3db8d241ba6ecab0b
5
5
  SHA512:
6
- metadata.gz: 408eb311bf8f0953b2feb9fbd1cc3ae52156633753530931acb5b5f3c20f0f07139ed08b9fa123e2fb2e64f777da3c66fa92968f639b77c33f9a5e8358512fe3
7
- data.tar.gz: 05d8d038f043348839ccb8d437c5dad826717a3f20878635a0afd028d485a65a97c6806d760e3c480dfea0878a3a008cb1a61820cc7b7f094c1beecea7d0c95a
6
+ metadata.gz: 5b249ffbc6783c5f8b9bbd443e999096087328661aa111879862d715ee85adb801290d8d0033a0c74b7002277490421c7e9d945fa016a8cde44970c297eba91a
7
+ data.tar.gz: 5d544679cdab55ef73e59895d38cad72cde505b640042b93645ad803c124d652b5f4f638a58ec0af53c5e1347305c3cb0d2fc937b235d5fb88a2c696be9c6662
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Groovy
2
+
3
+ An ORM for Groonga.
4
+
5
+
data/lib/groovy/query.rb CHANGED
@@ -28,7 +28,7 @@ module Groovy
28
28
  def search(obj)
29
29
  obj.each do |col, q|
30
30
  unless model.index_columns.include?(col)
31
- raise "Not an index column, so cannot do fulltext search: #{col}"
31
+ raise "Not an index column, so cannot do fulltext search: #{col}"
32
32
  end
33
33
  parameters.push(AND + "(#{col}:@#{q})")
34
34
  end
@@ -48,9 +48,9 @@ module Groovy
48
48
 
49
49
  def find_each(&block)
50
50
  in_batches(of: 10) do |group|
51
- group.each { |item| yield(item) }
51
+ group.each { |item| yield(item) }
52
52
  end
53
- end
53
+ end
54
54
 
55
55
  # http://groonga.org/docs/reference/grn_expr/query_syntax.html
56
56
  # TODO: support match_columns (search value in two or more columns)
@@ -119,7 +119,7 @@ module Groovy
119
119
  end
120
120
  self
121
121
  end
122
-
122
+
123
123
  def limit(num)
124
124
  @sorting[:limit] = num
125
125
  self
@@ -174,7 +174,7 @@ module Groovy
174
174
  def each(&block)
175
175
  records.each { |r| block.call(r) }
176
176
  end
177
-
177
+
178
178
  def total_entries
179
179
  results # ensure query has been run
180
180
  @total_entries
@@ -210,7 +210,7 @@ module Groovy
210
210
 
211
211
  def add_param(param)
212
212
  if parameters.include?(param)
213
- raise "Duplicate param: #{param}"
213
+ raise "Duplicate param: #{param}"
214
214
  end
215
215
 
216
216
  # if param matches blank/nil, put at the end of the stack
@@ -236,9 +236,9 @@ module Groovy
236
236
  @total_entries = set.size
237
237
 
238
238
  puts "Sorting with #{sort_key_and_order}, #{sorting.inspect}" if ENV['DEBUG']
239
- set = set.sort(sort_key_and_order, {
240
- limit: sorting[:limit],
241
- offset: sorting[:offset]
239
+ set = set.sort(sort_key_and_order, {
240
+ limit: sorting[:limit],
241
+ offset: sorting[:offset]
242
242
  })
243
243
 
244
244
  sorting[:group_by] ? set.group(group_by) : set
@@ -261,9 +261,11 @@ module Groovy
261
261
  def prepare_query
262
262
  space_regex = Regexp.new('\s([' + VALID_QUERY_CHARS + '])')
263
263
  query = parameters.join(' ').split(/ or /i).map do |part|
264
- part.gsub(' ', ' ').gsub(space_regex, '\ \1')
264
+ part.gsub(' ', ' ') # replace double with single spaces
265
+ .gsub(space_regex, '\ \1') # escape spaces before word letters
266
+ .gsub(/(\d\d):(\d\d):(\d\d)/, '\1\:\2\:\3') # escape hh:mm:ss in timestamps
265
267
  end.join(' OR ').sub(/^-/, '_id:>0 -') #.gsub(' OR -', ' -')
266
268
  end
267
269
  end
268
270
 
269
- end
271
+ end
data/lib/groovy/schema.rb CHANGED
@@ -98,7 +98,7 @@ module Groovy
98
98
 
99
99
  def switch_to_context(db_context)
100
100
  log("Switching context to #{db_context}")
101
- @context = db_context
101
+ @context = db_context
102
102
  @table = @search_table = nil # clear cached vars
103
103
  end
104
104
 
@@ -120,7 +120,7 @@ module Groovy
120
120
  default_tokenizer: "TokenBigram"
121
121
  })
122
122
  log("Creating search table with options: #{opts.inspect}")
123
- Groonga::Schema.create_table(SEARCH_TABLE_NAME, opts.merge(context: context))
123
+ Groonga::Schema.create_table(SEARCH_TABLE_NAME, opts.merge(context: context))
124
124
  end
125
125
 
126
126
  def remove_columns_not_in(list)
@@ -138,7 +138,7 @@ module Groovy
138
138
  end
139
139
 
140
140
  def has_column?(name, type = nil)
141
- table.columns.any? do |col|
141
+ table.columns.any? do |col|
142
142
  col && col.name == "#{table_name}.#{name}" # && (type.nil? or col.type == type)
143
143
  end
144
144
  end
@@ -1,3 +1,3 @@
1
1
  module Groovy
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.2.5'.freeze
3
3
  end
data/spec/query_spec.rb CHANGED
@@ -55,6 +55,30 @@ describe Groovy::Query do
55
55
  end
56
56
  end
57
57
 
58
+ describe 'lower/greater than search (timestamps)' do
59
+ before do
60
+ @one_week_ago = Time.now - (3600 * 24 * 7)
61
+ @p3.update_attributes(created_at: Time.at(@one_week_ago.to_i))
62
+ end
63
+
64
+ it 'finds expected records' do
65
+ res = TestProduct.where(created_at: @one_week_ago)
66
+ expect(res.map(&:id)).to eq([@p3.id])
67
+
68
+ res = TestProduct.where("created_at > #{@one_week_ago.to_s}")
69
+ expect(res.map(&:id)).to eq([@p1.id, @p2.id, @p4.id, @p5.id])
70
+
71
+ res = TestProduct.where("created_at < #{Time.now.to_s}")
72
+ expect(res.map(&:id)).to eq([@p3.id])
73
+
74
+ eight_days = Time.at(@one_week_ago.to_i - 3600 * 24)
75
+ six_days = Time.at(@one_week_ago.to_i + 3600 * 24)
76
+
77
+ res = TestProduct.where("created_at < #{six_days}").where("created_at > #{eight_days}")
78
+ expect(res.map(&:id)).to eq([@p3.id])
79
+ end
80
+ end
81
+
58
82
  context 'basic regex' do
59
83
  it 'finds expected records' do
60
84
  res = TestProduct.where(tag_list: /two/)
data/spec/spec_helper.rb CHANGED
@@ -13,7 +13,7 @@ RSpec.configure do |config|
13
13
  end
14
14
  end
15
15
 
16
- class TestProduct
16
+ class TestProduct
17
17
  include Groovy::Model
18
18
  end
19
19
 
@@ -23,6 +23,7 @@ def load_schema!(context_name)
23
23
  t.string :name
24
24
  t.integer :price
25
25
  t.string :tag_list
26
+ t.timestamps
26
27
  end
27
28
  end
28
29
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groovy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-18 00:00:00.000000000 Z
11
+ date: 2019-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rroonga
@@ -81,6 +81,7 @@ extra_rdoc_files: []
81
81
  files:
82
82
  - ".gitignore"
83
83
  - Gemfile
84
+ - README.md
84
85
  - Rakefile
85
86
  - example/Gemfile
86
87
  - example/Gemfile.lock
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  version: '0'
120
121
  requirements: []
121
122
  rubyforge_project:
122
- rubygems_version: 2.7.6
123
+ rubygems_version: 2.7.3
123
124
  signing_key:
124
125
  specification_version: 4
125
126
  summary: A wrapper around Groonga/Rroonga