groovy 0.4.7 → 0.5.0

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: 43812d3bd8ef9579ceed22b3d19e78378ceb3a924bfc8d6c0983e49199c26c88
4
- data.tar.gz: 5960ca73a253d62f31301995c8f643bcaa084a99140b5f59eee0161c816d20e2
3
+ metadata.gz: 334e9f5cb0dffab38a1bcd065ba7bedd4d4382ad79cc8c572044ebb0fd6f3586
4
+ data.tar.gz: 6fae9ad07b1e8316594e320da974d5aee980deaaca717c729a260004a221d8a8
5
5
  SHA512:
6
- metadata.gz: 22cc09a73d9804f5d5e1cb432d3948ff24ef9a28dbd84b5a403b3709477d013089617ebf19b23f4d3450c3c7dc8e15c01ab527698c5efa5821c9d351056777ad
7
- data.tar.gz: 809b9fa8e3158df7afeb6e80967d7156772094b21b69f6fe7d9f5e6db03626fe8a9b2ee123f89c7bf791ef6e195415524b1e967291d836becdc6173fbd0bfbfc
6
+ metadata.gz: fa11b79ead949a9f3595459a5b8b7baecb48ac30769e0586627f1d9753ec991a7e2a4a3f20e8cef12bf7f474e02fa30f8b347b9a7330db26fe39462496ed12a5
7
+ data.tar.gz: 113348c59d32fcefab72dfa707ce97e6972294454b5afb84e5e9e72bfe6c26538e6236161353d915827ae9962291437ac821d59c5d81ee86276a88d8630c7306
data/README.md CHANGED
@@ -2,4 +2,7 @@
2
2
 
3
3
  An ORM for Groonga.
4
4
 
5
+ # TODO:
6
+
7
+ - [ ] Allow using scopes/queries through Vector class.
5
8
 
data/example/relations.rb CHANGED
@@ -21,6 +21,7 @@ class Category
21
21
 
22
22
  schema do |t|
23
23
  t.string :name
24
+ t.reference :place, "Places"
24
25
  t.timestamps
25
26
  end
26
27
 
data/lib/groovy/model.rb CHANGED
@@ -26,7 +26,7 @@ module Groovy
26
26
  # end
27
27
 
28
28
  def self.model_from_table(table_name)
29
- Kernel.const_get(table_name.sub(/ies$/, 'y').sub(/s$/, '').capitalize)
29
+ Kernel.const_get(table_name.to_s.sub(/ies$/, 'y').sub(/s$/, '').classify)
30
30
  end
31
31
 
32
32
  def self.included(base)
@@ -190,14 +190,19 @@ module Groovy
190
190
  query_class.new(self, table)
191
191
  end
192
192
 
193
+ def scopes
194
+ @scopes ||= []
195
+ end
196
+
193
197
  def scope(name, obj)
198
+ scopes.push(name)
194
199
  query_class.add_scope(name, obj)
195
200
  define_singleton_method(name) do |*args|
196
201
  query.public_send(name, *args)
197
202
  end
198
203
  end
199
204
 
200
- [:first, :last, :select, :find_each, :find_by, :search, :where, :not, :sort_by, :limit, :offset, :paginate, :in_batches].each do |scope_method|
205
+ [:first, :last, :select, :find_by, :search, :where, :not, :sort_by, :limit, :offset, :paginate, :in_batches].each do |scope_method|
201
206
  define_method scope_method do |*args, &block|
202
207
  query.public_send(scope_method, *args, &block)
203
208
  end
data/lib/groovy/query.rb CHANGED
@@ -62,13 +62,13 @@ module Groovy
62
62
  where(conditions).limit(1).first
63
63
  end
64
64
 
65
- def find_each(opts = {}, &block)
66
- count = 0
67
- in_batches({ of: 10 }.merge(opts)) do |group|
68
- group.each { |item| count += 1; yield(item) }
69
- end
70
- count
71
- end
65
+ # def find_each(opts = {}, &block)
66
+ # count = 0
67
+ # in_batches({ of: 10 }.merge(opts)) do |group|
68
+ # group.each { |item| count += 1; yield(item) }
69
+ # end
70
+ # count
71
+ # end
72
72
 
73
73
  # http://groonga.org/docs/reference/grn_expr/query_syntax.html
74
74
  # TODO: support match_columns (search value in two or more columns)
data/lib/groovy/vector.rb CHANGED
@@ -74,9 +74,30 @@ module Groovy
74
74
 
75
75
  alias_method :<<, :push
76
76
 
77
+ [:first, :last, :find_by, :search, :where, :not, :sort_by, :limit, :offset, :paginate, :in_batches].each do |scope_method|
78
+ define_method scope_method do |*args, &block|
79
+ query.public_send(scope_method, *args, &block)
80
+ end
81
+ end
82
+
77
83
  private
78
84
  attr_reader :obj, :key
79
85
 
86
+ def query
87
+ model = Model.model_from_table(key.capitalize)
88
+ obj_name = obj.class.name.downcase
89
+ model.query.where(obj_name => obj.id)
90
+ end
91
+
92
+ def method_missing(name, *args, &block)
93
+ model = Model.model_from_table(key.capitalize)
94
+ if model.scopes.include?(name)
95
+ query.send(name)
96
+ else
97
+ super
98
+ end
99
+ end
100
+
80
101
  def remove_record(rec)
81
102
  recs = obj.record[key].delete_if { |r| r == rec }
82
103
  obj.record[key] = recs
@@ -1,3 +1,3 @@
1
1
  module Groovy
2
- VERSION = '0.4.7'.freeze
2
+ VERSION = '0.5.0'.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.7
4
+ version: 0.5.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: 2020-10-14 00:00:00.000000000 Z
11
+ date: 2022-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rroonga