aliyun-log 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aliyun/log/record/relation.rb +66 -9
- data/lib/aliyun/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: 0365cd8d407b5198a7e6ce3ea9e0aeac77f4af1954a7373a5817e3454a0d72ad
|
4
|
+
data.tar.gz: '0842353fac8ae79d4972e351437b8435137169eb41929085796bc70c30973d88'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91b72a67855c9850b9b21eb1930f4d1c1118cb8068e3172e9ffd6db15e214003592671f1b5705b2b60f32abe458b4843683946bc837de8118d075855a7ba2cbd
|
7
|
+
data.tar.gz: 5926791f61bb63e367337c4bb7b8c284d3aa04d4c94f4ba9966aa54317db53ce75e5dbc4953d804088ec0cd96bfca25af88d18f7e828b3712b06316d457e9cd5
|
@@ -10,9 +10,9 @@ module Aliyun
|
|
10
10
|
@klass.auto_load_schema
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def inspect
|
14
|
+
"#<#{self.class}>"
|
15
|
+
end
|
16
16
|
|
17
17
|
def first(line = 1)
|
18
18
|
find_offset(0, line, false)
|
@@ -93,7 +93,10 @@ module Aliyun
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def sql(*statement)
|
96
|
-
|
96
|
+
unless statement[0].is_a?(String)
|
97
|
+
raise ParseStatementInvalid, 'Only support string statement'
|
98
|
+
end
|
99
|
+
ql = sanitize_array(*statement)
|
97
100
|
@opts[:sql] = ql if ql.present?
|
98
101
|
self
|
99
102
|
end
|
@@ -151,11 +154,23 @@ module Aliyun
|
|
151
154
|
return search_content unless search_content.is_a?(Hash)
|
152
155
|
|
153
156
|
search_content.select { |_, v| v.present? }.map do |key, value|
|
154
|
-
|
157
|
+
options = @klass.attributes[:"#{key}"]
|
158
|
+
unless options
|
155
159
|
raise UnknownAttributeError, "unknown field '#{key}' for #{@klass.name}."
|
156
160
|
end
|
157
161
|
|
158
|
-
|
162
|
+
raise_if_hash_quote(value)
|
163
|
+
|
164
|
+
cast_type = options[:cast_type]
|
165
|
+
if value.is_a?(Array)
|
166
|
+
values = value.uniq.map { |v| _quote(cast_type, v) }
|
167
|
+
str_values = values.map { |v| "#{key}: #{v}" }.join(' OR ')
|
168
|
+
values.size > 1 ? "(#{str_values})" : str_values
|
169
|
+
elsif value.is_a?(Range)
|
170
|
+
"#{key} in [#{value.begin} #{value.end}]"
|
171
|
+
else
|
172
|
+
"#{key}: #{_quote(cast_type, value)}"
|
173
|
+
end
|
159
174
|
end.join(' AND ')
|
160
175
|
end
|
161
176
|
|
@@ -165,7 +180,7 @@ module Aliyun
|
|
165
180
|
replace_named_bind_variables(statement, values.first)
|
166
181
|
elsif statement.include?('?')
|
167
182
|
replace_bind_variables(statement, values)
|
168
|
-
elsif statement.blank?
|
183
|
+
elsif statement.blank? || values.blank?
|
169
184
|
statement
|
170
185
|
else
|
171
186
|
statement % values.collect(&:to_s)
|
@@ -175,7 +190,14 @@ module Aliyun
|
|
175
190
|
def replace_named_bind_variables(statement, bind_vars)
|
176
191
|
statement.gsub(/(:?):([a-zA-Z]\w*)/) do |match|
|
177
192
|
if bind_vars.include?(match = Regexp.last_match(2).to_sym)
|
178
|
-
|
193
|
+
match_value = bind_vars[match]
|
194
|
+
raise_if_hash_quote(match_value)
|
195
|
+
if match_value.is_a?(Array) || match_value.is_a?(Range)
|
196
|
+
values = match_value.map { |v| _quote_type_value(v) }
|
197
|
+
values.join(', ')
|
198
|
+
else
|
199
|
+
_quote_type_value(match_value)
|
200
|
+
end
|
179
201
|
else
|
180
202
|
raise ParseStatementInvalid, "missing value for :#{match} in #{statement}"
|
181
203
|
end
|
@@ -191,7 +213,42 @@ module Aliyun
|
|
191
213
|
end
|
192
214
|
bound = values.dup
|
193
215
|
statement.gsub(/\?/) do
|
194
|
-
|
216
|
+
value = bound.shift
|
217
|
+
raise_if_hash_quote(value)
|
218
|
+
if value.is_a?(Array) || value.is_a?(Range)
|
219
|
+
values = value.map { |v| _quote_type_value(v) }
|
220
|
+
values.join(', ')
|
221
|
+
else
|
222
|
+
_quote_type_value(value)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def _quote(type, value)
|
228
|
+
v = TypeCasting.dump_field(value, cast_type: type || :string)
|
229
|
+
case type
|
230
|
+
when :string, nil then "'#{v.to_s}'"
|
231
|
+
when :bigdecimal then v.to_s("F")
|
232
|
+
when :integer then v.to_s.to_i
|
233
|
+
when :datetime, :date then "'#{v.iso8601}'"
|
234
|
+
else
|
235
|
+
value.to_s
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def _quote_type_value(value)
|
240
|
+
case value.class.name
|
241
|
+
when 'String' then "'#{value.to_s}'"
|
242
|
+
when 'BigDecimal' then value.to_s("F")
|
243
|
+
when 'Date', 'DateTime', 'Time' then "'#{value.iso8601}'"
|
244
|
+
else
|
245
|
+
value
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def raise_if_hash_quote(value)
|
250
|
+
if value.is_a?(Hash) || value.is_a?(ActiveSupport::HashWithIndifferentAccess)
|
251
|
+
raise ParseStatementInvalid, "can't quote Hash"
|
195
252
|
end
|
196
253
|
end
|
197
254
|
|
data/lib/aliyun/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aliyun-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yingce Liu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|