baseapi 0.1.12 → 0.1.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3e73410c8406195ecee9cafea68fb5e51af7002
4
- data.tar.gz: f42abb494021317b75fcc3fdb59f56665eb93a0c
3
+ metadata.gz: a6f8c5e16034693c92e956e421277975f060297c
4
+ data.tar.gz: 6ecded08bc1d03c2f3b434e4d7d688b6a43c0aad
5
5
  SHA512:
6
- metadata.gz: 94f9e21eec63f75e68802a9e7b881ece8925d639c58068289a98e327c4b174061f9e5c3e4e0deaae158163fca87dc66914ac421f758c7ccc36b2ab1e5941c23a
7
- data.tar.gz: f279474c03b69be2619384c31cda734dd836a9e5171acbdf34f443d3c2e2c5f17638d9adede9265e6006e5ecb9f52b4510f71292a7c7612642c3d2639e7780c5
6
+ metadata.gz: eaee6b87986d514a069f07c5f15a1b42b0d3df9e4fc3865069cea4268319566df49dd107893af8be047dbc117659e92231c5bede60311d6cd4d9b67d86edfe18
7
+ data.tar.gz: d1702cfa15dc126229ac95b00b9b7bf07c0bc03c81b48da1d206cf16006c2bab78707d4eda25e04903262686f5430e5684d45755233c72c207202f0ffebc6df2
data/README.md CHANGED
@@ -223,6 +223,27 @@ Delete the id to 1
223
223
  ]
224
224
  }
225
225
 
226
+ ### reserved word (v0.1.13~)
227
+
228
+ We are using the following as a reserved word.
229
+
230
+ - count
231
+ - page
232
+ - order
233
+ - orderby
234
+
235
+ It can not be used as a column name in the database.
236
+
237
+ But, you can be avoided by specifying the prefix.
238
+
239
+ class User < ActiveRecord::Base
240
+ @reserved_word_prefix = '_'
241
+ end
242
+
243
+ You can request as follows in doing so
244
+
245
+ GET /users.json?_count=10&_page=2
246
+
226
247
  ### Override
227
248
 
228
249
  You can corresponding to the logical deletion, if you want to search condition to like and or, you will be able to override the processing in the Model
@@ -1,5 +1,7 @@
1
1
  module ActiveRecordBaseExtension extend ActiveSupport::Concern
2
2
 
3
+ @reserved_word_prefix = ''
4
+
3
5
  # override if necessary
4
6
  def _destroy
5
7
  destroy
@@ -7,6 +9,12 @@ module ActiveRecordBaseExtension extend ActiveSupport::Concern
7
9
 
8
10
  module ClassMethods
9
11
 
12
+ # reserved word prefix(count,page,order,orderby...)
13
+ # @return String
14
+ def get_reserved_word_prefix
15
+ @reserved_word_prefix
16
+ end
17
+
10
18
  # override if necessary
11
19
  # @return ActiveRecordRelation
12
20
  def _all
@@ -16,24 +16,24 @@ module ActiveRecordRelationExtension
16
16
  models = self.model.send(function_name, models, key, values)
17
17
  # belongs_to, has_many search
18
18
  else
19
- relationSearch = -> (models, currentModel, key, value, prifix = '', joins = []) {
19
+ relationSearch = -> (models, currentModel, key, value, prefix = '', joins = []) {
20
20
  joins.push key
21
21
  associations = currentModel.get_associations()
22
22
  associations.keys.each do |association|
23
23
  if currentModel.column_names.include?(key)
24
24
  # call function
25
- function_name = self.model.methods.include?("_#{prifix}_#{joins.join('_')}".to_sym) ? "_#{prifix}_#{joins.join('_')}" : "_#{prifix}"
25
+ function_name = self.model.methods.include?("_#{prefix}_#{joins.join('_')}".to_sym) ? "_#{prefix}_#{joins.join('_')}" : "_#{prefix}"
26
26
  table_name = currentModel.name.underscore
27
27
  hash = {key => value}
28
28
  return self.model.send(function_name, models, table_name, hash)
29
29
  elsif associations[association].include?(key)
30
- # prifix = first association
31
- prifix = association if prifix == ''
30
+ # prefix = first association
31
+ prefix = association if prefix == ''
32
32
  models.joins_array!(joins)
33
33
  currentModel = key.camelize.singularize.constantize
34
34
  value.each do |k, v|
35
35
  # this fnuction collback
36
- models = relationSearch.call(models, currentModel, k, v, prifix, joins)
36
+ models = relationSearch.call(models, currentModel, k, v, prefix, joins)
37
37
  end
38
38
  end
39
39
  end
@@ -49,8 +49,9 @@ module ActiveRecordRelationExtension
49
49
  # pager
50
50
  # @param Hash params
51
51
  def paging!(params)
52
- count = params[:count].present? ? params[:count].to_i : -1;
53
- page = params[:page].present? ? params[:page].to_i : 1;
52
+ prefix = self.model.get_reserved_word_prefix
53
+ count = params["#{prefix}count".to_sym].present? ? params["#{prefix}count".to_sym].to_i : -1;
54
+ page = params["#{prefix}page".to_sym].present? ? params["#{prefix}page".to_sym].to_i : 1;
54
55
  if count > 0
55
56
  if count.present? and count
56
57
  limit!(count)
@@ -64,8 +65,9 @@ module ActiveRecordRelationExtension
64
65
  # sort
65
66
  # @param Hash params
66
67
  def sorting!(params)
67
- if params[:order].present? and params[:orderby].present?
68
- order!({params[:orderby] => params[:order]})
68
+ prefix = self.model.get_reserved_word_prefix
69
+ if params["#{prefix}order".to_sym].present? and params["#{prefix}orderby".to_sym].present?
70
+ order!({params["#{prefix}orderby".to_sym] => params["#{prefix}order".to_sym]})
69
71
  end
70
72
  end
71
73
 
@@ -1,3 +1,3 @@
1
1
  module Baseapi
2
- VERSION = "0.1.12"
2
+ VERSION = "0.1.13"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baseapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moriyuki Arakawa