groovy 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/groovy.rb +8 -0
- data/lib/groovy/model.rb +7 -1
- data/lib/groovy/query.rb +14 -5
- data/lib/groovy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2e735dd501cd86a3ee2ab21b111bf7aa4ab3d76d9d14acf8be86b97e34335b1
|
4
|
+
data.tar.gz: 97b3b88d1f297ab6d74b9818858272c8fa711a27a3c0d64964508988a3304b85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: deb85e6549f328555d795e542e282c6e3a50c574fdac769530648c69292f02ed469bc293304db863b7c9ac28a5bb653bd85eb79a7652f6390b3f5309fc492552
|
7
|
+
data.tar.gz: 7546011290684eca615cf4823df5886908fe823c9bee086a80504a01a7d3aa846a0fd34dc05efc023a061078ac3645d352618c64a03b614989cb51bc3ca4c5c9
|
data/lib/groovy.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'groonga'
|
2
2
|
require File.expand_path(File.dirname(__FILE__)) + '/groovy/model'
|
3
3
|
|
4
|
+
# overwrite Groonga::Record#inspect because the #attributes part is
|
5
|
+
# making debugging take ages
|
6
|
+
class Groonga::Record
|
7
|
+
def inspect
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
module Groovy
|
5
13
|
|
6
14
|
class Error < StandardError; end
|
data/lib/groovy/model.rb
CHANGED
@@ -208,7 +208,7 @@ module Groovy
|
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
|
-
[:find_each, :find_by, :search, :where, :not, :sort_by, :limit, :offset, :paginate, :in_batches].each do |scope_method|
|
211
|
+
[:select, :find_each, :find_by, :search, :where, :not, :sort_by, :limit, :offset, :paginate, :in_batches].each do |scope_method|
|
212
212
|
define_method scope_method do |*args, &block|
|
213
213
|
query.public_send(scope_method, *args, &block)
|
214
214
|
end
|
@@ -309,6 +309,12 @@ module Groovy
|
|
309
309
|
@changes = {}
|
310
310
|
end
|
311
311
|
|
312
|
+
# get reference to the actual record in the Groonga table,
|
313
|
+
# not the temporary one we get as part of a search result.
|
314
|
+
def load_record
|
315
|
+
self.class.table[id]
|
316
|
+
end
|
317
|
+
|
312
318
|
def inspect
|
313
319
|
"#<#{self.class.name} id:#{id.inspect} attributes:[#{self.class.attribute_names.join(', ')}]>"
|
314
320
|
end
|
data/lib/groovy/query.rb
CHANGED
@@ -47,6 +47,11 @@ module Groovy
|
|
47
47
|
self
|
48
48
|
end
|
49
49
|
|
50
|
+
def select(&block)
|
51
|
+
@select_block = block
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
50
55
|
def find(id)
|
51
56
|
find_by(_id: id)
|
52
57
|
end
|
@@ -141,10 +146,10 @@ module Groovy
|
|
141
146
|
self
|
142
147
|
end
|
143
148
|
|
144
|
-
def paginate(page = 1)
|
149
|
+
def paginate(page = 1, per_page: PER_PAGE)
|
145
150
|
page = 1 if page.to_i < 1
|
146
|
-
offset = ((page.to_i)-1) *
|
147
|
-
offset(offset).limit(
|
151
|
+
offset = ((page.to_i)-1) * per_page
|
152
|
+
offset(offset).limit(per_page) # returns self
|
148
153
|
end
|
149
154
|
|
150
155
|
# sort_by(title: :asc)
|
@@ -229,9 +234,10 @@ module Groovy
|
|
229
234
|
end
|
230
235
|
|
231
236
|
private
|
232
|
-
attr_reader :model, :table, :options
|
237
|
+
attr_reader :model, :table, :options, :select_block
|
233
238
|
|
234
239
|
def add_param(param)
|
240
|
+
raise "Select block already given!" if select_block
|
235
241
|
raise "Duplicate param: #{param}" if parameters.include?(param)
|
236
242
|
parameters.push(param)
|
237
243
|
end
|
@@ -244,7 +250,10 @@ module Groovy
|
|
244
250
|
end
|
245
251
|
|
246
252
|
def execute
|
247
|
-
set = if
|
253
|
+
set = if select_block
|
254
|
+
debug "Finding records with select block"
|
255
|
+
table.select { |record| select_block.call(record) }
|
256
|
+
elsif parameters.any?
|
248
257
|
query = prepare_query
|
249
258
|
debug "Finding records with query: #{query}"
|
250
259
|
table.select(query, options)
|
data/lib/groovy/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.2
|
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: 2020-10-
|
11
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rroonga
|