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 +4 -4
- data/README.md +3 -0
- data/example/relations.rb +1 -0
- data/lib/groovy/model.rb +7 -2
- data/lib/groovy/query.rb +7 -7
- data/lib/groovy/vector.rb +21 -0
- 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: 334e9f5cb0dffab38a1bcd065ba7bedd4d4382ad79cc8c572044ebb0fd6f3586
|
4
|
+
data.tar.gz: 6fae9ad07b1e8316594e320da974d5aee980deaaca717c729a260004a221d8a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa11b79ead949a9f3595459a5b8b7baecb48ac30769e0586627f1d9753ec991a7e2a4a3f20e8cef12bf7f474e02fa30f8b347b9a7330db26fe39462496ed12a5
|
7
|
+
data.tar.gz: 113348c59d32fcefab72dfa707ce97e6972294454b5afb84e5e9e72bfe6c26538e6236161353d915827ae9962291437ac821d59c5d81ee86276a88d8630c7306
|
data/README.md
CHANGED
data/example/relations.rb
CHANGED
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$/, '').
|
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, :
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
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
|
+
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:
|
11
|
+
date: 2022-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rroonga
|