baseapi 0.1.7 → 0.1.8

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: 2c43cc198f8095f49cc275feb31170f0af5f72c1
4
- data.tar.gz: 4a0ae6530a6150ae894be6424a956381fae09b86
3
+ metadata.gz: ef45b44ae0098c0c40a9e073515b5a3679ae5622
4
+ data.tar.gz: eed6e1caf5fce76b7bc20df167c75a1bfe46fb48
5
5
  SHA512:
6
- metadata.gz: fdae87d0508923b64d14e9f77562f38304c9b76ddf630715406d37609bb8f831f6473e83064f27b876f7924abdfd4ba16ba434804dbcee91738c6fc2984d8f7b
7
- data.tar.gz: 7ff5f9e7aecd8be6fdff8679b3637744bbc0abcfe76924689782e33bcf5c5b2b446b8d6b5dc41b07b630a29952cd2eecba54f91abbbec39341b96e82680eb685
6
+ metadata.gz: 4c7cb5e7a57770324319d81853e74008cb9863a82e2425ea0410c6046faece2e3b4ecc8e7b7e805160a50556dbc1a1638b0c17eff289b9a8ff07204f9480507f
7
+ data.tar.gz: cec57dc2393488280ad6e7bf5d7d8e7da8f513687499683150c902a5885ccadf51bbf5c714b993c54568f464ad397a681eb5eeb86584cd512ce765b01553c8cb
data/README.md CHANGED
@@ -117,6 +117,28 @@ Of course the other is also possible (v0.1.7~)
117
117
 
118
118
  GET /users.json?name=!hoge
119
119
 
120
+ Specify the null name (v0.1.7~)
121
+
122
+ GET /users.json?name=null
123
+
124
+ Specify the not null name (v0.1.7~)
125
+
126
+ GET /users.json?name=!null
127
+
128
+ Specify the empty string and null name (v0.1.8~)
129
+
130
+ GET /users.json?name=empty
131
+
132
+ Specify the not empty string and null name (v0.1.8~)
133
+
134
+ GET /users.json?name=!empty
135
+
136
+ Specify search for simply string 'empty' (v0.1.8~)
137
+
138
+ It can also be in double quotes "empty"
139
+
140
+ GET /users.json?name='empty'
141
+
120
142
  Specify the belongs to company name
121
143
 
122
144
  Note that this is a single
@@ -29,7 +29,7 @@ module ActiveRecordBaseExtension extend ActiveSupport::Concern
29
29
  # @option String operator 'or' or 'and'
30
30
  def column_match(models, column, values, operator:'or')
31
31
  column_call(models, column, values, ->(column, value){
32
- "#{getPrefix(value)} #{models.name.pluralize.underscore}.#{column} #{getOperator(value)} #{getValue(value, "'")}"
32
+ "#{getPrefix(value)} #{models.name.pluralize.underscore}.#{column} #{getOperator(value)} #{getValue("#{models.name.pluralize.underscore}.#{column}", value, "'")}"
33
33
  }, operator:operator)
34
34
  end
35
35
 
@@ -40,7 +40,7 @@ module ActiveRecordBaseExtension extend ActiveSupport::Concern
40
40
  # @option String operator 'or' or 'and'
41
41
  def column_like(models, column, values, operator:'or')
42
42
  column_call(models, column, values, ->(column, value){
43
- "#{getPrefix(value)} #{models.name.pluralize.underscore}.#{column} like #{getValue(value, "%", "'")}"
43
+ "#{getPrefix(value)} #{models.name.pluralize.underscore}.#{column} #{getOperator(value, 'like')} #{getValue("#{models.name.pluralize.underscore}.#{column}", value, "%", "'")}"
44
44
  }, operator:operator)
45
45
  end
46
46
 
@@ -79,7 +79,7 @@ module ActiveRecordBaseExtension extend ActiveSupport::Concern
79
79
  # @option String operator 'or' or 'and'
80
80
  def relation_match(models, table, hash, operator:'or')
81
81
  relation_call(models, table, hash, ->(table, column, value){
82
- "#{getPrefix(value)} #{table}.#{column} #{getOperator(value)} #{getValue(value, "'")}"
82
+ "#{getPrefix(value)} #{table}.#{column} #{getOperator(value)} #{getValue("#{table}.#{column}", value, "'")}"
83
83
  }, operator:operator)
84
84
  end
85
85
 
@@ -90,7 +90,7 @@ module ActiveRecordBaseExtension extend ActiveSupport::Concern
90
90
  # @option String operator 'or' or 'and'
91
91
  def relation_like(models, table, hash, operator:'or')
92
92
  relation_call(models, table, hash, ->(table, column, value){
93
- "#{getPrefix(value)} #{table}.#{column} like #{getValue(value, "%", "'")}"
93
+ "#{getPrefix(value)} #{table}.#{column} #{getOperator(value, 'like')} #{getValue("#{table}.#{column}", value, "%", "'")}"
94
94
  }, operator:operator)
95
95
  end
96
96
 
@@ -120,19 +120,26 @@ module ActiveRecordBaseExtension extend ActiveSupport::Concern
120
120
  # return = or IS
121
121
  # @param String value
122
122
  # @return String operator
123
- def getOperator(value)
124
- (value.gsub('!', '').upcase == 'NULL') ? 'IS' : '='
123
+ def getOperator(value, default = '=')
124
+ ['NULL', 'EMPTY'].include?(value.gsub('!', '').upcase) ? 'IS' : default
125
125
  end
126
126
 
127
127
  # slice '!' value
128
+ # @param String column
128
129
  # @param String value
129
130
  # @param String wraps ' or %
130
- # @return String value
131
- def getValue(value, *wraps)
131
+ # @return String value or sql
132
+ def getValue(column, value, *wraps)
133
+ original = value.clone
132
134
  value.slice!(0) if value[0] == '!'
133
135
  if value.upcase == 'NULL'
134
136
  value = 'NULL'
137
+ elsif value.upcase == 'EMPTY'
138
+ prefix = getPrefix(original)
139
+ operator = prefix == 'NOT' ? 'AND' : 'OR'
140
+ value = "NULL #{operator} #{prefix} #{column} = ''"
135
141
  else
142
+ value = getNaturalValue(value)
136
143
  wraps.each do |wrap|
137
144
  value = "#{wrap}#{value}#{wrap}"
138
145
  end
@@ -140,6 +147,16 @@ module ActiveRecordBaseExtension extend ActiveSupport::Concern
140
147
  return value
141
148
  end
142
149
 
150
+ # removal of the enclosing
151
+ # @param String value
152
+ # @return String value
153
+ def getNaturalValue(value)
154
+ if ((/^[\'].+?[\']$/ =~ value) != nil) and ((/^[\"].+?[\"]$/ =~ value) != nil)
155
+ value.gsub!(/^[\'\"]/, '').gsub!(/[\'\"]$/, '')
156
+ end
157
+ value
158
+ end
159
+
143
160
 
144
161
  # get relation tables
145
162
  # @param String relate 'belongs_to','hasmany'..
@@ -1,3 +1,3 @@
1
1
  module Baseapi
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
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.7
4
+ version: 0.1.8
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-19 00:00:00.000000000 Z
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler