groovy 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/groovy.gemspec +1 -1
- data/lib/groovy/model.rb +9 -5
- data/lib/groovy/query.rb +17 -1
- data/lib/groovy/version.rb +1 -1
- data/lib/groovy.rb +3 -3
- data/spec/groovy_spec.rb +12 -0
- data/spec/query_spec.rb +2 -2
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3e87c857a45ab045967ed1af60d619ec7340fc751c950032645657049bd1c68
|
4
|
+
data.tar.gz: 4886e8db94b7fa3627312f82842d141b9c24ea7954e59955f4840dab7f70f776
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df4c68551089cf9ade2f20ac70436962fff82c0a83db5caeb0208b107a1215443386ab429d644c939200fef844a70db315c502cfb4c901aff7c809f578a07b67
|
7
|
+
data.tar.gz: 8eb292ae1c4365040a62c4f9feb8e04b27119ae5b4d84b1adf0640cb7f1d46cbea29bafd57ad076ca0d0f593fae504f4bb6eb4afac392b530f725f82948b8ad1
|
data/Gemfile
CHANGED
data/groovy.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
# s.required_rubygems_version = ">= 1.3.6"
|
15
15
|
# s.rubyforge_project = "groovy"
|
16
16
|
|
17
|
-
s.add_runtime_dependency "rroonga", "=
|
17
|
+
s.add_runtime_dependency "rroonga", "= 12.1.0"
|
18
18
|
|
19
19
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
20
20
|
s.add_development_dependency "rspec", '~> 3.0', '>= 3.0.0'
|
data/lib/groovy/model.rb
CHANGED
@@ -202,9 +202,13 @@ module Groovy
|
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
-
|
206
|
-
|
207
|
-
|
205
|
+
def where(*args, &block)
|
206
|
+
query.where(*args, &block)
|
207
|
+
end
|
208
|
+
|
209
|
+
[:first, :last, :select, :find_by, :search, :not, :sort_by, :in_batches, :limit, :offset, :paginate].each do |scope_method|
|
210
|
+
define_method scope_method do |**args, &block|
|
211
|
+
query.public_send(scope_method, **args, &block)
|
208
212
|
end
|
209
213
|
end
|
210
214
|
|
@@ -231,7 +235,7 @@ module Groovy
|
|
231
235
|
end
|
232
236
|
|
233
237
|
def set_timestamp(obj, key_name)
|
234
|
-
obj[key_name] = Time.now if attribute_names.include?(key_name.to_sym)
|
238
|
+
obj[key_name] = Time.now.utc if attribute_names.include?(key_name.to_sym)
|
235
239
|
end
|
236
240
|
|
237
241
|
def callbacks
|
@@ -256,7 +260,7 @@ module Groovy
|
|
256
260
|
end
|
257
261
|
|
258
262
|
def db_context
|
259
|
-
Groovy.contexts[context_name
|
263
|
+
Groovy.contexts[context_name&.to_sym] \
|
260
264
|
or raise "Context not defined: #{context_name} Please call Groovy.open('./db/path') first."
|
261
265
|
end
|
262
266
|
|
data/lib/groovy/query.rb
CHANGED
@@ -75,7 +75,7 @@ module Groovy
|
|
75
75
|
def where(conditions = nil)
|
76
76
|
case conditions
|
77
77
|
when String # "foo:bar"
|
78
|
-
add_param(AND + "(#{map_operator(conditions)})")
|
78
|
+
add_param(AND + "(#{map_operator(handle_timestamps(conditions))})")
|
79
79
|
when Hash # { foo: 'bar' } or { views: 1..100 }
|
80
80
|
conditions.each do |key, val|
|
81
81
|
if val.is_a?(Range)
|
@@ -91,6 +91,15 @@ module Groovy
|
|
91
91
|
str = "#{key}:#{val.join(" OR #{key}:")}"
|
92
92
|
add_param(AND + str)
|
93
93
|
|
94
|
+
elsif val.is_a?(Time)
|
95
|
+
# The second, specify the timestamp as string in following format:
|
96
|
+
# “(YEAR)/(MONTH)/(DAY) (HOUR):(MINUTE):(SECOND)”
|
97
|
+
|
98
|
+
# date_str = val.utc.strftime("%Y/%m/%d %H\:%M\:%S")
|
99
|
+
date_str = val.strftime("%Y/%m/%d %H\:%M\:%S")
|
100
|
+
str = "#{key}:#{date_str}"
|
101
|
+
add_param(AND + str)
|
102
|
+
|
94
103
|
else
|
95
104
|
str = val.nil? || val === false || val.to_s.strip == '' ? "\"\"" : escape_val(val)
|
96
105
|
add_param(AND + [key, str].join(':'))
|
@@ -229,6 +238,7 @@ module Groovy
|
|
229
238
|
end
|
230
239
|
|
231
240
|
def in_batches(of: 1000, from: nil, &block)
|
241
|
+
puts "of: #{of}"
|
232
242
|
sorting[:limit] = of
|
233
243
|
sorting[:offset] = from || 0
|
234
244
|
|
@@ -305,6 +315,12 @@ module Groovy
|
|
305
315
|
.sub(' >= ', ':>=')
|
306
316
|
end
|
307
317
|
|
318
|
+
# remove timezones from timestamps, otherwise we get a 'failed to cast to <Time>' error
|
319
|
+
def handle_timestamps(str)
|
320
|
+
# 2023-11-21 10:38:17 -0300 -> 2023/11/21 10:38:17
|
321
|
+
str.sub(/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+) (.+)/, '\1/\2/\3 \4:\5:\6')
|
322
|
+
end
|
323
|
+
|
308
324
|
def sort_key_and_order
|
309
325
|
sorting[:by] or [{ key: @default_sort_key, order: :asc }]
|
310
326
|
end
|
data/lib/groovy/version.rb
CHANGED
data/lib/groovy.rb
CHANGED
@@ -41,7 +41,7 @@ module Groovy
|
|
41
41
|
contexts[name.to_sym] = if name == :default
|
42
42
|
Groonga::Context.default.tap { |ctx| open_or_create_db(ctx, db_path) }
|
43
43
|
else
|
44
|
-
init_context(db_path
|
44
|
+
init_context(db_path)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -63,8 +63,8 @@ module Groovy
|
|
63
63
|
|
64
64
|
private
|
65
65
|
|
66
|
-
def init_context(db_path
|
67
|
-
Groonga::Context.new
|
66
|
+
def init_context(db_path)
|
67
|
+
Groonga::Context.new.tap do |ctx|
|
68
68
|
open_or_create_db(ctx, db_path)
|
69
69
|
end
|
70
70
|
end
|
data/spec/groovy_spec.rb
CHANGED
@@ -5,6 +5,18 @@ describe Groovy do
|
|
5
5
|
Groonga::Context.default = nil
|
6
6
|
end
|
7
7
|
|
8
|
+
it 'explodes if opening a scheme without opening first' do
|
9
|
+
expect do
|
10
|
+
class Foobar; end
|
11
|
+
Foobar.class_eval do
|
12
|
+
include Groovy::Model
|
13
|
+
schema do |t|
|
14
|
+
t.string :foobar
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end.to raise_error("Context not defined: Please call Groovy.open('./db/path') first.")
|
18
|
+
end
|
19
|
+
|
8
20
|
describe '.open' do
|
9
21
|
it 'explodes if called with no params' do
|
10
22
|
expect do
|
data/spec/query_spec.rb
CHANGED
@@ -95,10 +95,10 @@ describe Groovy::Query do
|
|
95
95
|
res = TestProduct.where(created_at: @one_week_ago)
|
96
96
|
expect(res.map(&:id)).to eq([@p3.id])
|
97
97
|
|
98
|
-
res = TestProduct.where("created_at > #{@one_week_ago
|
98
|
+
res = TestProduct.where("created_at > #{@one_week_ago}")
|
99
99
|
expect(res.map(&:id)).to eq([@p1.id, @p2.id, @p4.id, @p5.id])
|
100
100
|
|
101
|
-
res = TestProduct.where("created_at < #{Time.now
|
101
|
+
res = TestProduct.where("created_at < #{Time.now}")
|
102
102
|
expect(res.map(&:id)).to eq([@p3.id])
|
103
103
|
|
104
104
|
eight_days = Time.at(@one_week_ago.to_i - 3600 * 24)
|
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.
|
4
|
+
version: 0.6.0
|
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:
|
11
|
+
date: 2023-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rroonga
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 12.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 12.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
|
-
|
124
|
-
rubygems_version: 2.7.3
|
123
|
+
rubygems_version: 3.4.10
|
125
124
|
signing_key:
|
126
125
|
specification_version: 4
|
127
126
|
summary: A wrapper around Groonga/Rroonga
|