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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b64b5151ebc9ad89b92fac064613d778e067449e11eb0c87cbf8ce40ca5e2630
4
- data.tar.gz: 3e95ca4bac3946bcf79805c174216be0cb2870c06e47369056054bfb4d61a637
3
+ metadata.gz: c2e735dd501cd86a3ee2ab21b111bf7aa4ab3d76d9d14acf8be86b97e34335b1
4
+ data.tar.gz: 97b3b88d1f297ab6d74b9818858272c8fa711a27a3c0d64964508988a3304b85
5
5
  SHA512:
6
- metadata.gz: 3320e1c8e3d31b9d48c2fbf409f2688b3be16734eebd631b9ee44f9509934968079b9ed1ab14a02422a559865e2619da1954640feed825bc17b8865ab96ac4d1
7
- data.tar.gz: 1d1ebb476d22fa504a2b1f7ef7585f298fb5fbc84dbdc22cb34997c1a8e57032622e0c12867aab730bf75f08293d7f093a49059efb68d11c150be5684e4c9c34
6
+ metadata.gz: deb85e6549f328555d795e542e282c6e3a50c574fdac769530648c69292f02ed469bc293304db863b7c9ac28a5bb653bd85eb79a7652f6390b3f5309fc492552
7
+ data.tar.gz: 7546011290684eca615cf4823df5886908fe823c9bee086a80504a01a7d3aa846a0fd34dc05efc023a061078ac3645d352618c64a03b614989cb51bc3ca4c5c9
@@ -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
@@ -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
@@ -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) * PER_PAGE
147
- offset(offset).limit(PER_PAGE) # returns self
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 parameters.any?
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)
@@ -1,3 +1,3 @@
1
1
  module Groovy
2
- VERSION = '0.4.1'.freeze
2
+ VERSION = '0.4.2'.freeze
3
3
  end
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.1
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-07 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rroonga