hotdog 0.1.14 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hotdog/commands/search.rb +124 -62
- data/lib/hotdog/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: 6ba5e711471dbce8fac64967560afa8b2904e7e1
|
4
|
+
data.tar.gz: 0830641057b9783f128fd820011b7f9a81225917
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0bd65901e52513e7bbbd1f3ca94b40fcb84c040ce0322f7228272c9eb4df04a70101b67fa00f43cb71d27013e7a3d55e35c0f6d6dea85a33f39eb9102c9eac6
|
7
|
+
data.tar.gz: 7dc374d284be65129be03043c2b8cbf1d1b8b238c7473c4b54d1af7b563dc4168eb84bfbd939c7fa54f166595f0f039f8390c2427c2d859489ce54bbe41ddd78
|
@@ -108,9 +108,12 @@ module Hotdog
|
|
108
108
|
| spacing.maybe >> identifier_glob.as(:identifier_glob) >> separator >> attribute_glob.as(:attribute_glob) >> spacing.maybe \
|
109
109
|
| spacing.maybe >> identifier_glob.as(:identifier_glob) >> separator >> attribute.as(:attribute) >> spacing.maybe \
|
110
110
|
| spacing.maybe >> identifier_glob.as(:identifier_glob) >> spacing.maybe \
|
111
|
-
| spacing.maybe >> identifier.as(:identifier)>> separator >> attribute_glob.as(:attribute_glob) >> spacing.maybe \
|
112
|
-
| spacing.maybe >> identifier.as(:identifier)>> separator >> attribute.as(:attribute) >> spacing.maybe \
|
111
|
+
| spacing.maybe >> identifier.as(:identifier) >> separator >> attribute_glob.as(:attribute_glob) >> spacing.maybe \
|
112
|
+
| spacing.maybe >> identifier.as(:identifier) >> separator >> attribute.as(:attribute) >> spacing.maybe \
|
113
113
|
| spacing.maybe >> identifier.as(:identifier) >> spacing.maybe \
|
114
|
+
| spacing.maybe >> attribute_regexp.as(:attribute_regexp) >> spacing.maybe \
|
115
|
+
| spacing.maybe >> attribute_glob.as(:attribute_glob) >> spacing.maybe \
|
116
|
+
| spacing.maybe >> attribute.as(:attribute) >> spacing.maybe \
|
114
117
|
)
|
115
118
|
}
|
116
119
|
rule(:identifier_regexp) {
|
@@ -182,6 +185,15 @@ module Hotdog
|
|
182
185
|
rule(:identifier => simple(:identifier)) {
|
183
186
|
TagExpressionNode.new(identifier.to_s, nil)
|
184
187
|
}
|
188
|
+
rule(:attribute_regexp => simple(:attribute_regexp)) {
|
189
|
+
TagRegexpExpressionNode.new(nil, attribute_regexp.to_s)
|
190
|
+
}
|
191
|
+
rule(:attribute_glob => simple(:attribute_glob)) {
|
192
|
+
TagGlobExpressionNode.new(nil, attribute_glob.to_s)
|
193
|
+
}
|
194
|
+
rule(:attribute => simple(:attribute)) {
|
195
|
+
TagExpressionNode.new(nil, attribute.to_s)
|
196
|
+
}
|
185
197
|
end
|
186
198
|
|
187
199
|
class ExpressionNode
|
@@ -247,44 +259,58 @@ module Hotdog
|
|
247
259
|
|
248
260
|
class TagExpressionNode < ExpressionNode
|
249
261
|
def initialize(identifier, attribute)
|
250
|
-
|
251
|
-
|
252
|
-
else
|
253
|
-
@identifier = identifier
|
254
|
-
@attribute = attribute
|
255
|
-
end
|
262
|
+
@identifier = identifier
|
263
|
+
@attribute = attribute
|
256
264
|
end
|
257
265
|
attr_reader :identifier
|
258
266
|
attr_reader :attribute
|
267
|
+
def identifier?
|
268
|
+
!identifier.nil?
|
269
|
+
end
|
259
270
|
def attribute?
|
260
271
|
!attribute.nil?
|
261
272
|
end
|
262
273
|
def evaluate(environment)
|
263
|
-
if
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
274
|
+
if identifier?
|
275
|
+
if attribute?
|
276
|
+
case identifier
|
277
|
+
when /\Ahost\z/i
|
278
|
+
values = environment.execute(<<-EOS, attribute).map { |row| row.first }
|
279
|
+
SELECT hosts_tags.id FROM hosts
|
280
|
+
WHERE LOWER(hosts.name) = LOWER(?);
|
281
|
+
EOS
|
282
|
+
else
|
283
|
+
values = environment.execute(<<-EOS, identifier, attribute).map { |row| row.first }
|
284
|
+
SELECT DISTINCT hosts_tags.host_id FROM hosts_tags
|
285
|
+
INNER JOIN tags ON hosts_tags.tag_id = tags.id
|
286
|
+
WHERE LOWER(tags.name) = LOWER(?) AND LOWER(tags.value) = LOWER(?);
|
287
|
+
EOS
|
288
|
+
end
|
289
|
+
else
|
290
|
+
values = environment.execute(<<-EOS, identifier, identifier, identifier).map { |row| row.first }
|
291
|
+
SELECT DISTINCT hosts_tags.host_id FROM hosts_tags
|
292
|
+
INNER JOIN hosts ON hosts_tags.host_id = hosts.id
|
293
|
+
INNER JOIN tags ON hosts_tags.tag_id = tags.id
|
294
|
+
WHERE LOWER(hosts.name) = LOWER(?) OR LOWER(tags.name) = LOWER(?) OR LOWER(tags.value) = LOWER(?);
|
295
|
+
EOS
|
296
|
+
end
|
269
297
|
else
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
298
|
+
if attribute?
|
299
|
+
values = environment.execute(<<-EOS, attribute).map { |row| row.first }
|
300
|
+
SELECT DISTINCT hosts_tags.host_id FROM hosts_tags
|
301
|
+
INNER JOIN tags ON hosts_tags.tag_id = tags.id
|
302
|
+
WHERE LOWER(tags.value) = LOWER(?);
|
303
|
+
EOS
|
304
|
+
else
|
305
|
+
values = []
|
306
|
+
end
|
276
307
|
end
|
277
308
|
if not environment.fixed_string? and values.empty?
|
278
309
|
# fallback to glob expression
|
279
|
-
identifier_glob = identifier.gsub(/[-.\/_]/, "?")
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
environment.logger.info("fallback to glob expression: %s:%s" % [identifier_glob, attribute_glob])
|
284
|
-
else
|
285
|
-
attribute_glob = nil
|
286
|
-
environment.logger.info("fallback to glob expression: %s" % [identifier_glob])
|
287
|
-
end
|
310
|
+
identifier_glob = identifier.gsub(/[-.\/_]/, "?") if identifier?
|
311
|
+
attribute_glob = attribute.gsub(/[-.\/_]/, "?") if attribute?
|
312
|
+
if (identifier? and identifier != identifier_glob) or (attribute? and attribute != attribute_glob)
|
313
|
+
environment.logger.info("fallback to glob expression: %s:%s" % [identifier_glob, attribute_glob])
|
288
314
|
values = TagGlobExpressionNode.new(identifier_glob, attribute_glob).evaluate(environment)
|
289
315
|
end
|
290
316
|
end
|
@@ -294,31 +320,46 @@ module Hotdog
|
|
294
320
|
|
295
321
|
class TagGlobExpressionNode < TagExpressionNode
|
296
322
|
def evaluate(environment)
|
297
|
-
if
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
323
|
+
if identifier?
|
324
|
+
if attribute?
|
325
|
+
case identifier
|
326
|
+
when /\Ahost\z/i
|
327
|
+
values = environment.execute(<<-EOS, attribute).map { |row| row.first }
|
328
|
+
SELECT hosts.id FROM hosts
|
329
|
+
WHERE LOWER(hosts.name) GLOB LOWER(?);
|
330
|
+
EOS
|
331
|
+
else
|
332
|
+
values = environment.execute(<<-EOS, identifier, attribute).map { |row| row.first }
|
333
|
+
SELECT DISTINCT hosts_tags.host_id FROM hosts_tags
|
334
|
+
INNER JOIN tags ON hosts_tags.tag_id = tags.id
|
335
|
+
WHERE LOWER(tags.name) GLOB LOWER(?) AND LOWER(tags.value) GLOB LOWER(?);
|
336
|
+
EOS
|
337
|
+
end
|
338
|
+
else
|
339
|
+
values = environment.execute(<<-EOS, identifier, identifier, identifier).map { |row| row.first }
|
340
|
+
SELECT DISTINCT hosts_tags.host_id FROM hosts_tags
|
341
|
+
INNER JOIN hosts ON hosts_tags.host_id = hosts.id
|
342
|
+
INNER JOIN tags ON hosts_tags.tag_id = tags.id
|
343
|
+
WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);
|
344
|
+
EOS
|
345
|
+
end
|
303
346
|
else
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
347
|
+
if attribute?
|
348
|
+
values = environment.execute(<<-EOS, attribute).map { |row| row.first }
|
349
|
+
SELECT DISTINCT hosts_tags.host_id FROM hosts_tags
|
350
|
+
INNER JOIN tags ON hosts_tags.tag_id = tags.id
|
351
|
+
WHERE LOWER(tags.value) GLOB LOWER(?);
|
352
|
+
EOS
|
353
|
+
else
|
354
|
+
values = []
|
355
|
+
end
|
310
356
|
end
|
311
357
|
if not environment.fixed_string? and values.empty?
|
312
358
|
# fallback to glob expression
|
313
|
-
identifier_glob = identifier.gsub(/[-.\/_]/, "?")
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
environment.logger.info("fallback to glob expression: %s:%s" % [identifier_glob, attribute_glob])
|
318
|
-
else
|
319
|
-
attribute_glob = nil
|
320
|
-
environment.logger.info("fallback to glob expression: %s" % [identifier_glob])
|
321
|
-
end
|
359
|
+
identifier_glob = identifier.gsub(/[-.\/_]/, "?") if identifier?
|
360
|
+
attribute_glob = attribute.gsub(/[-.\/:_]/, "?") if attribute?
|
361
|
+
if (identifier? and identifier != identifier_glob) or (attribute? and attribute != attribute_glob)
|
362
|
+
environment.logger.info("fallback to glob expression: %s:%s" % [identifier_glob, attribute_glob])
|
322
363
|
values = TagGlobExpressionNode.new(identifier_glob, attribute_glob).evaluate(environment)
|
323
364
|
end
|
324
365
|
end
|
@@ -333,20 +374,41 @@ module Hotdog
|
|
333
374
|
super(identifier, attribute)
|
334
375
|
end
|
335
376
|
def evaluate(environment)
|
336
|
-
if
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
377
|
+
if identifier?
|
378
|
+
if attribute?
|
379
|
+
case identifier
|
380
|
+
when /\Ahost\z/i
|
381
|
+
values = environment.execute(<<-EOS, attribute).map { |row| row.first }
|
382
|
+
SELECT hosts_tags.id FROM hosts
|
383
|
+
WHERE LOWER(hosts.name) REGEXP LOWER(?);
|
384
|
+
EOS
|
385
|
+
else
|
386
|
+
environment.execute(<<-EOS, identifier, attribute).map { |row| row.first }
|
387
|
+
SELECT DISTINCT hosts_tags.host_id FROM hosts_tags
|
388
|
+
INNER JOIN tags ON hosts_tags.tag_id = tags.id
|
389
|
+
WHERE LOWER(tags.name) REGEXP LOWER(?) AND LOWER(tags.value) REGEXP LOWER(?);
|
390
|
+
EOS
|
391
|
+
end
|
392
|
+
else
|
393
|
+
environment.execute(<<-EOS, identifier, identifier, identifier).map { |row| row.first }
|
394
|
+
SELECT DISTINCT hosts_tags.host_id FROM hosts_tags
|
395
|
+
INNER JOIN hosts ON hosts_tags.host_id = hosts.id
|
396
|
+
INNER JOIN tags ON hosts_tags.tag_id = tags.id
|
397
|
+
WHERE LOWER(hosts.name) REGEXP LOWER(?) OR LOWER(tags.name) REGEXP LOWER(?) OR LOWER(tags.value) REGEXP LOWER(?);
|
398
|
+
EOS
|
399
|
+
end
|
342
400
|
else
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
401
|
+
if attribute?
|
402
|
+
values = environment.execute(<<-EOS, attribute).map { |row| row.first }
|
403
|
+
SELECT DISTINCT hosts_tags.host_id FROM hosts_tags
|
404
|
+
INNER JOIN tags ON hosts_tags.tag_id = tags.id
|
405
|
+
WHERE LOWER(tags.value) REGEXP LOWER(?);
|
406
|
+
EOS
|
407
|
+
else
|
408
|
+
values = []
|
409
|
+
end
|
349
410
|
end
|
411
|
+
values
|
350
412
|
end
|
351
413
|
end
|
352
414
|
end
|
data/lib/hotdog/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotdog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yamashita Yuu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|