api_helper 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 9efe86fda7179ba792ecf18057ebf0b1445d7f83
4
- data.tar.gz: 9f17ca34299833efa46df0e68a1f75d1470d269b
3
+ metadata.gz: aeda154cc88246fbd37bbce92133f4e73feee7a7
4
+ data.tar.gz: 403c2eb669b8b1ba866f4cec3875f44bf35528ef
5
5
  SHA512:
6
- metadata.gz: fcfd8f2af69946d843ebfd2f0579ef44f8db74b816c9a6843df7fd5cdb95565b8f93a3f5767b195089cec00f5b0a9894f7cf69300c133fb1116da37a43f4118b
7
- data.tar.gz: eb80f9bd80df82e8ae784b4b4a368c39c47d63ce16a910025d225d3197af26501d3e0e8bfff7be5cfe9ab002d62ba3c022fed09487dd4d1d10ae3671075ee5e6
6
+ metadata.gz: 55d8d8cc853e75cf8d75c2fc45523a35d773daffbf289e5df47d016b2e95378a05801c2a909d78687195ade2787253d2b8501ef852ed441475bed783438b3d51
7
+ data.tar.gz: c15c43fe4804b574b458ebeba1f8e2c55865cee75d6bedd42e53c0c103d189813f1c382aba5bc5c314e011accf84f91da24f27bff9fd6ce631b8663c2b64d8d8
@@ -91,6 +91,14 @@ module APIHelper::Filterable
91
91
 
92
92
  # if a function is used
93
93
  if func = condition.match(/(?<function>[^\(\)]+)\((?<param>.*)\)/)
94
+
95
+ db_column_name = begin
96
+ raise if ActiveRecord::Base.configurations[Rails.env]['adapter'] != 'mysql2'
97
+ "`#{resource.table_name}`.`#{field}`"
98
+ rescue
99
+ "\"#{resource.table_name}\".\"#{field}\""
100
+ end
101
+
94
102
  case func[:function]
95
103
  when 'not'
96
104
  values = func[:param].split(',')
@@ -99,38 +107,38 @@ module APIHelper::Filterable
99
107
 
100
108
  when 'greater_then'
101
109
  resource = resource
102
- .where("\"#{resource.table_name}\".\"#{field}\" > ?",
110
+ .where("#{db_column_name} > ?",
103
111
  func[:param])
104
112
 
105
113
  when 'less_then'
106
114
  resource = resource
107
- .where("\"#{resource.table_name}\".\"#{field}\" < ?",
115
+ .where("#{db_column_name} < ?",
108
116
  func[:param])
109
117
 
110
118
  when 'greater_then_or_equal'
111
119
  resource = resource
112
- .where("\"#{resource.table_name}\".\"#{field}\" >= ?",
120
+ .where("#{db_column_name} >= ?",
113
121
  func[:param])
114
122
 
115
123
  when 'less_then_or_equal'
116
124
  resource = resource
117
- .where("\"#{resource.table_name}\".\"#{field}\" <= ?",
125
+ .where("#{db_column_name} <= ?",
118
126
  func[:param])
119
127
 
120
128
  when 'between'
121
129
  param = func[:param].split(',')
122
130
  resource = resource
123
- .where("\"#{resource.table_name}\".\"#{field}\" BETWEEN ? AND ?",
131
+ .where("#{db_column_name} BETWEEN ? AND ?",
124
132
  param.first, param.last)
125
133
 
126
134
  when 'like'
127
135
  resource = resource
128
- .where("\"#{resource.table_name}\".\"#{field}\" LIKE ?",
136
+ .where("#{db_column_name} LIKE ?",
129
137
  func[:param])
130
138
 
131
139
  when 'contains'
132
140
  resource = resource
133
- .where("\"#{resource.table_name}\".\"#{field}\" LIKE ?",
141
+ .where("#{db_column_name} LIKE ?",
134
142
  "%#{func[:param]}%")
135
143
 
136
144
  when 'null'
@@ -1,3 +1,3 @@
1
1
  module APIHelper
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-26 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler