baseapi 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -1
- data/lib/baseapi/active_record/base_extension.rb +0 -2
- data/lib/baseapi/active_record/relation_extension.rb +40 -9
- data/lib/baseapi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9458a084335b8367f4758d5e98a419d4255d9635
|
4
|
+
data.tar.gz: 275a2633ec64ce87a21eb077599f9f2bd5ba72b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2910253e825b666b784cb6eaa017ff36e1ee75a805fad23284eb8f287bd2b4b185b66fe7db24c0cbb9138eb13ff58623ac6b6188933ed8e13360c1471a11041
|
7
|
+
data.tar.gz: 200cae2049be21cf6f57ce06a330d16f3ba9771438e0812a1cce4097dae0f20f18fd6c1d31142a1ffd37378972fdd408480eed4d798379d1917adc57f326a19e
|
data/README.md
CHANGED
@@ -151,6 +151,12 @@ Note that this is a multiple
|
|
151
151
|
|
152
152
|
GET /companies.json?users[name]=hoge
|
153
153
|
|
154
|
+
Relationships can now specify multiple (v0.1.9~)
|
155
|
+
|
156
|
+
Specify the User belong to a development part company
|
157
|
+
|
158
|
+
GET /users.json?company[units][name]=development
|
159
|
+
|
154
160
|
#### action show
|
155
161
|
|
156
162
|
Get id 1
|
@@ -251,6 +257,10 @@ company belongs_to search
|
|
251
257
|
end
|
252
258
|
end
|
253
259
|
|
260
|
+
If there are multiple related belongs_to
|
261
|
+
|
262
|
+
def self._belongs_to_company_units_...(models, table, hash)
|
263
|
+
|
254
264
|
has_many search
|
255
265
|
|
256
266
|
class Company < ActiveRecord::Base
|
@@ -269,6 +279,9 @@ users has_many search
|
|
269
279
|
end
|
270
280
|
end
|
271
281
|
|
282
|
+
If there are multiple related has_many
|
283
|
+
|
284
|
+
def self._has_many_users_families_...(models, table, hash)
|
272
285
|
|
273
286
|
### like & match, or & and Search (v0.1.3~)
|
274
287
|
|
@@ -291,7 +304,7 @@ If the search process of the related table is to override
|
|
291
304
|
relation_match, you can use the relation_like function.
|
292
305
|
|
293
306
|
class User < ActiveRecord::Base
|
294
|
-
def self.
|
307
|
+
def self._belongs_to_company(models, table, hash)
|
295
308
|
relation_match(models, table, hash, operator:'or') # default is match OR
|
296
309
|
# relation_like(models, table, hash, operator:'or') # LIKE OR
|
297
310
|
# relation_like(models, table, hash, operator:'and') # LIKE AND
|
@@ -13,7 +13,6 @@ module ActiveRecordBaseExtension extend ActiveSupport::Concern
|
|
13
13
|
self.all
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
16
|
# override or create method '_where_{column}' if necessary
|
18
17
|
# @param ActiveRecordRelation models
|
19
18
|
# @param String column column name
|
@@ -100,7 +99,6 @@ module ActiveRecordBaseExtension extend ActiveSupport::Concern
|
|
100
99
|
# @param Callable callable
|
101
100
|
# @option String operator orかand
|
102
101
|
def relation_call(models, table, hash, callable, operator:'or')
|
103
|
-
models.joins!(table.to_sym)
|
104
102
|
hash.each do |column, value|
|
105
103
|
if column.present? and value.present?
|
106
104
|
relation_values = value.instance_of?(Array) ? value : [value]
|
@@ -4,9 +4,9 @@ module ActiveRecordRelationExtension
|
|
4
4
|
# @param Hash params
|
5
5
|
def filtering!(params)
|
6
6
|
models = self
|
7
|
-
associations = self.model.get_associations()
|
8
7
|
params.each do |key, value|
|
9
8
|
if key.present? and value.present?
|
9
|
+
# this model search
|
10
10
|
if column_names.include?(key)
|
11
11
|
# array change
|
12
12
|
values = value.instance_of?(Array) ? value : [value]
|
@@ -14,15 +14,30 @@ module ActiveRecordRelationExtension
|
|
14
14
|
# call function
|
15
15
|
function_name = self.model.methods.include?("_where_#{key}".to_sym) ? "_where_#{key}" : '_where'
|
16
16
|
models = self.model.send(function_name, models, key, values)
|
17
|
-
end
|
18
|
-
|
19
17
|
# belongs_to, has_many search
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
else
|
19
|
+
relationSearch = -> (models, currentModel, key, value, joins = []) {
|
20
|
+
associations = currentModel.get_associations()
|
21
|
+
associations.keys.each do |association|
|
22
|
+
if currentModel.column_names.include?(key)
|
23
|
+
# call function
|
24
|
+
function_name = self.model.methods.include?("_#{association}_#{joins.join('_')}".to_sym) ? "_#{association}_#{joins.join('_')}" : "_#{association}"
|
25
|
+
table_name = currentModel.name.underscore
|
26
|
+
hash = {key => value}
|
27
|
+
return self.model.send(function_name, models, table_name, hash)
|
28
|
+
elsif associations[association].include?(key)
|
29
|
+
joins.push key
|
30
|
+
models.joins_array!(joins)
|
31
|
+
currentModel = key.camelize.singularize.constantize
|
32
|
+
value.each do |k, v|
|
33
|
+
# this fnuction collback
|
34
|
+
models = relationSearch.call(models, currentModel, k, v, joins)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
return models
|
39
|
+
}
|
40
|
+
models = relationSearch.call(models, self.model, key, value)
|
26
41
|
end
|
27
42
|
end
|
28
43
|
end
|
@@ -51,4 +66,20 @@ module ActiveRecordRelationExtension
|
|
51
66
|
order!({params[:orderby] => params[:order]})
|
52
67
|
end
|
53
68
|
end
|
69
|
+
|
70
|
+
|
71
|
+
# joins as array params
|
72
|
+
# @param array param
|
73
|
+
def joins_array!(joins)
|
74
|
+
param = nil
|
75
|
+
joins.reverse.each_with_index do |join, index|
|
76
|
+
join = join.to_sym
|
77
|
+
if index == 0
|
78
|
+
param = join
|
79
|
+
else
|
80
|
+
param = {join => param}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
joins!(param)
|
84
|
+
end
|
54
85
|
end
|
data/lib/baseapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baseapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moriyuki Arakawa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|