hotdog 0.24.0 → 0.25.0
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.rb +19 -19
- data/lib/hotdog/commands/search.rb +4 -4
- data/lib/hotdog/commands/tags.rb +4 -4
- data/lib/hotdog/expression.rb +50 -50
- data/lib/hotdog/expression/semantics.rb +97 -93
- data/lib/hotdog/expression/syntax.rb +31 -31
- data/lib/hotdog/version.rb +1 -1
- data/spec/{parser → evaluator}/glob_expression_spec.rb +19 -14
- data/spec/{parser → evaluator}/regexp_expression_spec.rb +19 -14
- data/spec/{parser → evaluator}/string_expression_spec.rb +19 -14
- data/spec/optimizer/binary_expression_spec.rb +47 -0
- data/spec/optimizer/glob_expression_spec.rb +105 -0
- data/spec/optimizer/regexp_expression_spec.rb +55 -0
- data/spec/optimizer/string_expression_spec.rb +105 -0
- data/spec/optimizer/unary_expression_spec.rb +23 -0
- data/spec/parser/parser_spec.rb +82 -82
- metadata +18 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6cb5a21b306e4a1d4ba2ed3f56a32bccede9d3e
|
4
|
+
data.tar.gz: db352cb8caf7b6204b5af04cae89ade3bb3225a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f34769acd4326c2d965fee9e69587af995d1764e00318531e8d36fab9020f520aaa4cb57d5950a95938a895ac3359a4800cdae089673c59f5c280f1d16a4611
|
7
|
+
data.tar.gz: cbcafc9311ea4f8384f57065324c104d0948bc8f95ad0e5108a4479d319e603e2501a8cc25b89c00057fbdd0777585b6b5621e43ed1695b07091e6faa27dc1b5
|
data/lib/hotdog/commands.rb
CHANGED
@@ -89,8 +89,8 @@ module Hotdog
|
|
89
89
|
else
|
90
90
|
if 0 < tags.length
|
91
91
|
fields = tags.map { |tag|
|
92
|
-
|
93
|
-
|
92
|
+
tagname, _tagvalue = split_tag(tag)
|
93
|
+
tagname
|
94
94
|
}
|
95
95
|
get_hosts_fields(host_ids, fields)
|
96
96
|
else
|
@@ -99,7 +99,7 @@ module Hotdog
|
|
99
99
|
fields = [
|
100
100
|
@options[:primary_tag],
|
101
101
|
"host",
|
102
|
-
] + get_fields(host_ids).reject { |
|
102
|
+
] + get_fields(host_ids).reject { |tagname| tagname == @options[:primary_tag] }
|
103
103
|
get_hosts_fields(host_ids, fields)
|
104
104
|
else
|
105
105
|
fields = [
|
@@ -152,9 +152,9 @@ module Hotdog
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
-
result = fields.map { |
|
156
|
-
|
157
|
-
display_tag(
|
155
|
+
result = fields.map { |tagname|
|
156
|
+
tagvalue = field_values.fetch(tagname.downcase, nil)
|
157
|
+
display_tag(tagname, tagvalue)
|
158
158
|
}
|
159
159
|
[result, fields]
|
160
160
|
end
|
@@ -171,8 +171,8 @@ module Hotdog
|
|
171
171
|
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
172
172
|
"WHERE hosts_tags.host_id IN (%s) AND tags.name = ? " \
|
173
173
|
"GROUP BY hosts_tags.host_id, tags.name ORDER BY hosts_tags.host_id;" % host_ids.map { "?" }.join(", ")
|
174
|
-
r = execute(q, host_ids + [field]).map { |
|
175
|
-
[display_tag(
|
174
|
+
r = execute(q, host_ids + [field]).map { |tagname, tagvalue|
|
175
|
+
[display_tag(tagname, tagvalue)]
|
176
176
|
}
|
177
177
|
if r.empty?
|
178
178
|
host_ids.map { [nil] }
|
@@ -184,12 +184,12 @@ module Hotdog
|
|
184
184
|
[result, [field]]
|
185
185
|
end
|
186
186
|
|
187
|
-
def display_tag(
|
188
|
-
if
|
189
|
-
if
|
190
|
-
|
187
|
+
def display_tag(tagname, tagvalue)
|
188
|
+
if tagvalue
|
189
|
+
if tagvalue.empty?
|
190
|
+
tagname # use `tagname` as `tagvalue` for the tags without any values
|
191
191
|
else
|
192
|
-
|
192
|
+
tagvalue
|
193
193
|
end
|
194
194
|
else
|
195
195
|
nil
|
@@ -398,15 +398,15 @@ module Hotdog
|
|
398
398
|
end
|
399
399
|
|
400
400
|
def split_tag(tag)
|
401
|
-
|
402
|
-
[
|
401
|
+
tagname, tagvalue = tag.split(":", 2)
|
402
|
+
[tagname, tagvalue || ""]
|
403
403
|
end
|
404
404
|
|
405
|
-
def join_tag(
|
406
|
-
if
|
407
|
-
|
405
|
+
def join_tag(tagname, tagvalue)
|
406
|
+
if tagvalue.to_s.empty?
|
407
|
+
tagname
|
408
408
|
else
|
409
|
-
"#{
|
409
|
+
"#{tagname}:#{tagvalue}"
|
410
410
|
end
|
411
411
|
end
|
412
412
|
|
@@ -66,16 +66,16 @@ module Hotdog
|
|
66
66
|
case
|
67
67
|
when n[:left] && n[:right] then drilldown.(n[:left]) + drilldown.(n[:right])
|
68
68
|
when n[:expression] then drilldown.(n[:expression])
|
69
|
-
when n[:
|
69
|
+
when n[:tagname] then [n[:tagname]]
|
70
70
|
else []
|
71
71
|
end
|
72
72
|
}
|
73
73
|
if options[:display_search_tags]
|
74
|
-
|
74
|
+
tagnames = drilldown.call(node).map(&:to_s)
|
75
75
|
if options[:primary_tag]
|
76
|
-
tags = [options[:primary_tag]] +
|
76
|
+
tags = [options[:primary_tag]] + tagnames
|
77
77
|
else
|
78
|
-
tags =
|
78
|
+
tags = tagnames
|
79
79
|
end
|
80
80
|
else
|
81
81
|
tags = nil
|
data/lib/hotdog/commands/tags.rb
CHANGED
@@ -9,16 +9,16 @@ module Hotdog
|
|
9
9
|
show_tags(result)
|
10
10
|
else
|
11
11
|
tags = args.map { |tag| split_tag(tag) }
|
12
|
-
if tags.all? { |
|
12
|
+
if tags.all? { |_tagname, tagvalue| tagvalue.empty? }
|
13
13
|
result = tags.each_slice(SQLITE_LIMIT_COMPOUND_SELECT).flat_map { |tags|
|
14
14
|
q = "SELECT value FROM tags " \
|
15
|
-
"WHERE %s;" % tags.map { |
|
16
|
-
execute(q, tags.map { |
|
15
|
+
"WHERE %s;" % tags.map { |tagname, _tagvalue| glob?(tagname) ? "LOWER(name) GLOB LOWER(?)" : "name = ?" }.join(" OR ")
|
16
|
+
execute(q, tags.map { |tagname, _tagvalue| tagname }).map { |value| [value] }
|
17
17
|
}
|
18
18
|
else
|
19
19
|
result = tags.each_slice(SQLITE_LIMIT_COMPOUND_SELECT / 2).flat_map { |tags|
|
20
20
|
q = "SELECT value FROM tags " \
|
21
|
-
"WHERE %s;" % tags.map { |
|
21
|
+
"WHERE %s;" % tags.map { |tagname, tagvalue| (glob?(tagname) or glob?(tagvalue)) ? "( LOWER(name) GLOB LOWER(?) AND LOWER(value) GLOB LOWER(?) )" : "( name = ? AND value = ? )" }.join(" OR ")
|
22
22
|
execute(q, tags).map { |value| [value] }
|
23
23
|
}
|
24
24
|
end
|
data/lib/hotdog/expression.rb
CHANGED
@@ -63,100 +63,100 @@ module Hotdog
|
|
63
63
|
rule(unary_op: simple(:unary_op), expression: simple(:expression)) {
|
64
64
|
UnaryExpressionNode.new(unary_op, expression)
|
65
65
|
}
|
66
|
-
rule(
|
67
|
-
if "/host/" ==
|
68
|
-
RegexpHostNode.new(
|
66
|
+
rule(tagname_regexp: simple(:tagname_regexp), separator: simple(:separator), tagvalue_regexp: simple(:tagvalue_regexp)) {
|
67
|
+
if "/host/" == tagname_regexp
|
68
|
+
RegexpHostNode.new(tagvalue_regexp, separator)
|
69
69
|
else
|
70
|
-
RegexpTagNode.new(
|
70
|
+
RegexpTagNode.new(tagname_regexp, tagvalue_regexp, separator)
|
71
71
|
end
|
72
72
|
}
|
73
|
-
rule(
|
74
|
-
if "/host/" ==
|
73
|
+
rule(tagname_regexp: simple(:tagname_regexp), separator: simple(:separator)) {
|
74
|
+
if "/host/" == tagname_regexp
|
75
75
|
EverythingNode.new()
|
76
76
|
else
|
77
|
-
|
77
|
+
RegexpTagnameNode.new(tagname_regexp, separator)
|
78
78
|
end
|
79
79
|
}
|
80
|
-
rule(
|
81
|
-
if "/host/" ==
|
80
|
+
rule(tagname_regexp: simple(:tagname_regexp)) {
|
81
|
+
if "/host/" == tagname_regexp
|
82
82
|
EverythingNode.new()
|
83
83
|
else
|
84
|
-
RegexpHostOrTagNode.new(
|
84
|
+
RegexpHostOrTagNode.new(tagname_regexp)
|
85
85
|
end
|
86
86
|
}
|
87
|
-
rule(
|
88
|
-
if "host" ==
|
89
|
-
GlobHostNode.new(
|
87
|
+
rule(tagname_glob: simple(:tagname_glob), separator: simple(:separator), tagvalue_glob: simple(:tagvalue_glob)) {
|
88
|
+
if "host" == tagname_glob
|
89
|
+
GlobHostNode.new(tagvalue_glob, separator)
|
90
90
|
else
|
91
|
-
GlobTagNode.new(
|
91
|
+
GlobTagNode.new(tagname_glob, tagvalue_glob, separator)
|
92
92
|
end
|
93
93
|
}
|
94
|
-
rule(
|
95
|
-
if "host" ==
|
96
|
-
GlobHostNode.new(
|
94
|
+
rule(tagname_glob: simple(:tagname_glob), separator: simple(:separator), tagvalue: simple(:tagvalue)) {
|
95
|
+
if "host" == tagname_glob
|
96
|
+
GlobHostNode.new(tagvalue, separator)
|
97
97
|
else
|
98
|
-
GlobTagNode.new(
|
98
|
+
GlobTagNode.new(tagname_glob, tagvalue, separator)
|
99
99
|
end
|
100
100
|
}
|
101
|
-
rule(
|
102
|
-
if "host" ==
|
101
|
+
rule(tagname_glob: simple(:tagname_glob), separator: simple(:separator)) {
|
102
|
+
if "host" == tagname_glob
|
103
103
|
EverythingNode.new()
|
104
104
|
else
|
105
|
-
|
105
|
+
GlobTagnameNode.new(tagname_glob, separator)
|
106
106
|
end
|
107
107
|
}
|
108
|
-
rule(
|
109
|
-
if "host" ==
|
108
|
+
rule(tagname_glob: simple(:tagname_glob)) {
|
109
|
+
if "host" == tagname_glob
|
110
110
|
EverythingNode.new()
|
111
111
|
else
|
112
|
-
GlobHostOrTagNode.new(
|
112
|
+
GlobHostOrTagNode.new(tagname_glob)
|
113
113
|
end
|
114
114
|
}
|
115
|
-
rule(
|
116
|
-
if "host" ==
|
117
|
-
GlobHostNode.new(
|
115
|
+
rule(tagname: simple(:tagname), separator: simple(:separator), tagvalue_glob: simple(:tagvalue_glob)) {
|
116
|
+
if "host" == tagname
|
117
|
+
GlobHostNode.new(tagvalue_glob, separator)
|
118
118
|
else
|
119
|
-
GlobTagNode.new(
|
119
|
+
GlobTagNode.new(tagname, tagvalue_glob, separator)
|
120
120
|
end
|
121
121
|
}
|
122
|
-
rule(
|
123
|
-
if "host" ==
|
124
|
-
StringHostNode.new(
|
122
|
+
rule(tagname: simple(:tagname), separator: simple(:separator), tagvalue: simple(:tagvalue)) {
|
123
|
+
if "host" == tagname
|
124
|
+
StringHostNode.new(tagvalue, separator)
|
125
125
|
else
|
126
|
-
StringTagNode.new(
|
126
|
+
StringTagNode.new(tagname, tagvalue, separator)
|
127
127
|
end
|
128
128
|
}
|
129
|
-
rule(
|
130
|
-
if "host" ==
|
129
|
+
rule(tagname: simple(:tagname), separator: simple(:separator)) {
|
130
|
+
if "host" == tagname
|
131
131
|
EverythingNode.new()
|
132
132
|
else
|
133
|
-
|
133
|
+
StringTagnameNode.new(tagname, separator)
|
134
134
|
end
|
135
135
|
}
|
136
|
-
rule(
|
137
|
-
if "host" ==
|
136
|
+
rule(tagname: simple(:tagname)) {
|
137
|
+
if "host" == tagname
|
138
138
|
EverythingNode.new()
|
139
139
|
else
|
140
|
-
StringHostOrTagNode.new(
|
140
|
+
StringHostOrTagNode.new(tagname)
|
141
141
|
end
|
142
142
|
}
|
143
|
-
rule(separator: simple(:separator),
|
144
|
-
|
143
|
+
rule(separator: simple(:separator), tagvalue_regexp: simple(:tagvalue_regexp)) {
|
144
|
+
RegexpTagvalueNode.new(tagvalue_regexp, separator)
|
145
145
|
}
|
146
|
-
rule(
|
147
|
-
|
146
|
+
rule(tagvalue_regexp: simple(:tagvalue_regexp)) {
|
147
|
+
RegexpTagvalueNode.new(tagvalue_regexp)
|
148
148
|
}
|
149
|
-
rule(separator: simple(:separator),
|
150
|
-
|
149
|
+
rule(separator: simple(:separator), tagvalue_glob: simple(:tagvalue_glob)) {
|
150
|
+
GlobTagvalueNode.new(tagvalue_glob, separator)
|
151
151
|
}
|
152
|
-
rule(
|
153
|
-
|
152
|
+
rule(tagvalue_glob: simple(:tagvalue_glob)) {
|
153
|
+
GlobTagvalueNode.new(tagvalue_glob)
|
154
154
|
}
|
155
|
-
rule(separator: simple(:separator),
|
156
|
-
|
155
|
+
rule(separator: simple(:separator), tagvalue: simple(:tagvalue)) {
|
156
|
+
StringTagvalueNode.new(tagvalue, separator)
|
157
157
|
}
|
158
|
-
rule(
|
159
|
-
|
158
|
+
rule(tagvalue: simple(:tagvalue)) {
|
159
|
+
StringTagvalueNode.new(tagvalue)
|
160
160
|
}
|
161
161
|
end
|
162
162
|
end
|
@@ -14,6 +14,10 @@ module Hotdog
|
|
14
14
|
def dump(options={})
|
15
15
|
{}
|
16
16
|
end
|
17
|
+
|
18
|
+
def ==(other)
|
19
|
+
self.dump == other.dump
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
class UnaryExpressionNode < ExpressionNode
|
@@ -272,7 +276,7 @@ module Hotdog
|
|
272
276
|
end
|
273
277
|
when :XOR
|
274
278
|
if left == right
|
275
|
-
|
279
|
+
NothingNode.new(options)
|
276
280
|
else
|
277
281
|
optimize1(options)
|
278
282
|
end
|
@@ -355,7 +359,7 @@ module Hotdog
|
|
355
359
|
if query_without_condition
|
356
360
|
condition_length = expressions.map { |expression| expression.condition_values(options).length }.max
|
357
361
|
expressions.each_slice(SQLITE_LIMIT_COMPOUND_SELECT / condition_length).flat_map { |expressions|
|
358
|
-
q = query_without_condition.sub(/\s*;\s*\z/, "
|
362
|
+
q = query_without_condition.sub(/\s*;\s*\z/, " WHERE #{expressions.map { |expression| "( %s )" % expression.condition(options) }.join(" OR ")};")
|
359
363
|
environment.execute(q, expressions.flat_map { |expression| expression.condition_values(options) }).map { |row| row.first }
|
360
364
|
}
|
361
365
|
else
|
@@ -461,7 +465,7 @@ module Hotdog
|
|
461
465
|
@args[0] = @args[0].optimize(options)
|
462
466
|
if TagExpressionNode === args[1]
|
463
467
|
# workaround for expressions like `ORDER_BY((environment:development),role)`
|
464
|
-
@args[1] = @args[1].
|
468
|
+
@args[1] = @args[1].tagname
|
465
469
|
else
|
466
470
|
@args[1] = @args[1]
|
467
471
|
end
|
@@ -470,7 +474,7 @@ module Hotdog
|
|
470
474
|
if @args[1]
|
471
475
|
if TagExpressionNode === @args[1]
|
472
476
|
# workaround for expressions like `ORDER_BY((environment:development),role)`
|
473
|
-
@args[1] = @args[1].
|
477
|
+
@args[1] = @args[1].tagname
|
474
478
|
else
|
475
479
|
@args[1] = @args[1]
|
476
480
|
end
|
@@ -535,7 +539,7 @@ module Hotdog
|
|
535
539
|
|
536
540
|
class NothingNode < QueryExpressionNode
|
537
541
|
def initialize(options={})
|
538
|
-
super("SELECT NULL AS host_id WHERE host_id NOT NULL", [], options)
|
542
|
+
super("SELECT NULL AS host_id WHERE host_id NOT NULL;", [], options)
|
539
543
|
end
|
540
544
|
|
541
545
|
def evaluate(environment, options={})
|
@@ -548,22 +552,22 @@ module Hotdog
|
|
548
552
|
end
|
549
553
|
|
550
554
|
class TagExpressionNode < ExpressionNode
|
551
|
-
def initialize(
|
552
|
-
@
|
553
|
-
@
|
555
|
+
def initialize(tagname, tagvalue, separator=nil)
|
556
|
+
@tagname = tagname
|
557
|
+
@tagvalue = tagvalue
|
554
558
|
@separator = separator
|
555
559
|
@fallback = nil
|
556
560
|
end
|
557
|
-
attr_reader :
|
558
|
-
attr_reader :
|
561
|
+
attr_reader :tagname
|
562
|
+
attr_reader :tagvalue
|
559
563
|
attr_reader :separator
|
560
564
|
|
561
|
-
def
|
562
|
-
!(
|
565
|
+
def tagname?
|
566
|
+
!(tagname.nil? or tagname.to_s.empty?)
|
563
567
|
end
|
564
568
|
|
565
|
-
def
|
566
|
-
!(
|
569
|
+
def tagvalue?
|
570
|
+
!(tagvalue.nil? or tagvalue.to_s.empty?)
|
567
571
|
end
|
568
572
|
|
569
573
|
def separator?
|
@@ -573,7 +577,7 @@ module Hotdog
|
|
573
577
|
def maybe_query(options={})
|
574
578
|
query_without_condition = maybe_query_without_condition(options)
|
575
579
|
if query_without_condition
|
576
|
-
query_without_condition.sub(/\s*;\s*\z/, "
|
580
|
+
query_without_condition.sub(/\s*;\s*\z/, " WHERE #{condition(options)};")
|
577
581
|
else
|
578
582
|
nil
|
579
583
|
end
|
@@ -654,7 +658,7 @@ module Hotdog
|
|
654
658
|
end
|
655
659
|
|
656
660
|
def ==(other)
|
657
|
-
self.class == other.class and @
|
661
|
+
self.class == other.class and @tagname == other.tagname and @tagvalue == other.tagvalue
|
658
662
|
end
|
659
663
|
|
660
664
|
def optimize(options={})
|
@@ -685,9 +689,9 @@ module Hotdog
|
|
685
689
|
|
686
690
|
def dump(options={})
|
687
691
|
data = {}
|
688
|
-
data[:
|
692
|
+
data[:tagname] = tagname.to_s if tagname
|
689
693
|
data[:separator] = separator.to_s if separator
|
690
|
-
data[:
|
694
|
+
data[:tagvalue] = tagvalue.to_s if tagvalue
|
691
695
|
data[:fallback ] = @fallback.dump(options) if @fallback
|
692
696
|
data
|
693
697
|
end
|
@@ -719,8 +723,8 @@ module Hotdog
|
|
719
723
|
end
|
720
724
|
|
721
725
|
class StringHostNode < StringExpressionNode
|
722
|
-
def initialize(
|
723
|
-
super("host",
|
726
|
+
def initialize(tagvalue, separator=nil)
|
727
|
+
super("host", tagvalue.to_s, separator)
|
724
728
|
end
|
725
729
|
|
726
730
|
def condition(options={})
|
@@ -732,11 +736,11 @@ module Hotdog
|
|
732
736
|
end
|
733
737
|
|
734
738
|
def condition_values(options={})
|
735
|
-
[
|
739
|
+
[tagvalue]
|
736
740
|
end
|
737
741
|
|
738
742
|
def maybe_fallback(options={})
|
739
|
-
fallback = GlobHostNode.new(to_glob(
|
743
|
+
fallback = GlobHostNode.new(to_glob(tagvalue), separator)
|
740
744
|
query = fallback.maybe_query(options)
|
741
745
|
if query
|
742
746
|
QueryExpressionNode.new(query, fallback.condition_values(options))
|
@@ -747,8 +751,8 @@ module Hotdog
|
|
747
751
|
end
|
748
752
|
|
749
753
|
class StringTagNode < StringExpressionNode
|
750
|
-
def initialize(
|
751
|
-
super(
|
754
|
+
def initialize(tagname, tagvalue, separator=nil)
|
755
|
+
super(tagname.to_s, tagvalue.to_s, separator)
|
752
756
|
end
|
753
757
|
|
754
758
|
def condition(options={})
|
@@ -760,11 +764,11 @@ module Hotdog
|
|
760
764
|
end
|
761
765
|
|
762
766
|
def condition_values(options={})
|
763
|
-
[
|
767
|
+
[tagname, tagvalue]
|
764
768
|
end
|
765
769
|
|
766
770
|
def maybe_fallback(options={})
|
767
|
-
fallback = GlobTagNode.new(to_glob(
|
771
|
+
fallback = GlobTagNode.new(to_glob(tagname), to_glob(tagvalue), separator)
|
768
772
|
query = fallback.maybe_query(options)
|
769
773
|
if query
|
770
774
|
QueryExpressionNode.new(query, fallback.condition_values(options))
|
@@ -774,9 +778,9 @@ module Hotdog
|
|
774
778
|
end
|
775
779
|
end
|
776
780
|
|
777
|
-
class
|
778
|
-
def initialize(
|
779
|
-
super(
|
781
|
+
class StringTagnameNode < StringExpressionNode
|
782
|
+
def initialize(tagname, separator=nil)
|
783
|
+
super(tagname.to_s, nil, separator)
|
780
784
|
end
|
781
785
|
|
782
786
|
def condition(options={})
|
@@ -788,11 +792,11 @@ module Hotdog
|
|
788
792
|
end
|
789
793
|
|
790
794
|
def condition_values(options={})
|
791
|
-
[
|
795
|
+
[tagname]
|
792
796
|
end
|
793
797
|
|
794
798
|
def maybe_fallback(options={})
|
795
|
-
fallback =
|
799
|
+
fallback = GlobTagnameNode.new(to_glob(tagname), separator)
|
796
800
|
query = fallback.maybe_query(options)
|
797
801
|
if query
|
798
802
|
QueryExpressionNode.new(query, fallback.condition_values(options))
|
@@ -802,9 +806,9 @@ module Hotdog
|
|
802
806
|
end
|
803
807
|
end
|
804
808
|
|
805
|
-
class
|
806
|
-
def initialize(
|
807
|
-
super(nil,
|
809
|
+
class StringTagvalueNode < StringExpressionNode
|
810
|
+
def initialize(tagvalue, separator=nil)
|
811
|
+
super(nil, tagvalue.to_s, separator)
|
808
812
|
end
|
809
813
|
|
810
814
|
def condition(options={})
|
@@ -816,11 +820,11 @@ module Hotdog
|
|
816
820
|
end
|
817
821
|
|
818
822
|
def condition_values(options={})
|
819
|
-
[
|
823
|
+
[tagvalue, tagvalue]
|
820
824
|
end
|
821
825
|
|
822
826
|
def maybe_fallback(options={})
|
823
|
-
fallback =
|
827
|
+
fallback = GlobTagvalueNode.new(to_glob(tagvalue), separator)
|
824
828
|
query = fallback.maybe_query(options)
|
825
829
|
if query
|
826
830
|
QueryExpressionNode.new(query, fallback.condition_values(options))
|
@@ -831,8 +835,8 @@ module Hotdog
|
|
831
835
|
end
|
832
836
|
|
833
837
|
class StringHostOrTagNode < StringExpressionNode
|
834
|
-
def initialize(
|
835
|
-
super(
|
838
|
+
def initialize(tagname, separator=nil)
|
839
|
+
super(tagname.to_s, nil, separator)
|
836
840
|
end
|
837
841
|
|
838
842
|
def condition(options={})
|
@@ -844,11 +848,11 @@ module Hotdog
|
|
844
848
|
end
|
845
849
|
|
846
850
|
def condition_values(options={})
|
847
|
-
[
|
851
|
+
[tagname, tagname, tagname]
|
848
852
|
end
|
849
853
|
|
850
854
|
def maybe_fallback(options={})
|
851
|
-
fallback = GlobHostOrTagNode.new(to_glob(
|
855
|
+
fallback = GlobHostOrTagNode.new(to_glob(tagname), separator)
|
852
856
|
query = fallback.maybe_query(options)
|
853
857
|
if query
|
854
858
|
QueryExpressionNode.new(query, fallback.condition_values(options))
|
@@ -861,17 +865,17 @@ module Hotdog
|
|
861
865
|
class GlobExpressionNode < TagExpressionNode
|
862
866
|
def dump(options={})
|
863
867
|
data = {}
|
864
|
-
data[:
|
868
|
+
data[:tagname_glob] = tagname.to_s if tagname
|
865
869
|
data[:separator] = separator.to_s if separator
|
866
|
-
data[:
|
870
|
+
data[:tagvalue_glob] = tagvalue.to_s if tagvalue
|
867
871
|
data[:fallback] = @fallback.dump(options) if @fallback
|
868
872
|
data
|
869
873
|
end
|
870
874
|
end
|
871
875
|
|
872
876
|
class GlobHostNode < GlobExpressionNode
|
873
|
-
def initialize(
|
874
|
-
super("host",
|
877
|
+
def initialize(tagvalue, separator=nil)
|
878
|
+
super("host", tagvalue.to_s, separator)
|
875
879
|
end
|
876
880
|
|
877
881
|
def condition(options={})
|
@@ -883,11 +887,11 @@ module Hotdog
|
|
883
887
|
end
|
884
888
|
|
885
889
|
def condition_values(options={})
|
886
|
-
[
|
890
|
+
[tagvalue]
|
887
891
|
end
|
888
892
|
|
889
893
|
def maybe_fallback(options={})
|
890
|
-
fallback = GlobHostNode.new(to_glob(
|
894
|
+
fallback = GlobHostNode.new(to_glob(tagvalue), separator)
|
891
895
|
query = fallback.maybe_query(options)
|
892
896
|
if query
|
893
897
|
QueryExpressionNode.new(query, fallback.condition_values(options))
|
@@ -898,8 +902,8 @@ module Hotdog
|
|
898
902
|
end
|
899
903
|
|
900
904
|
class GlobTagNode < GlobExpressionNode
|
901
|
-
def initialize(
|
902
|
-
super(
|
905
|
+
def initialize(tagname, tagvalue, separator=nil)
|
906
|
+
super(tagname.to_s, tagvalue.to_s, separator)
|
903
907
|
end
|
904
908
|
|
905
909
|
def condition(options={})
|
@@ -911,11 +915,11 @@ module Hotdog
|
|
911
915
|
end
|
912
916
|
|
913
917
|
def condition_values(options={})
|
914
|
-
[
|
918
|
+
[tagname, tagvalue]
|
915
919
|
end
|
916
920
|
|
917
921
|
def maybe_fallback(options={})
|
918
|
-
fallback = GlobTagNode.new(to_glob(
|
922
|
+
fallback = GlobTagNode.new(to_glob(tagname), to_glob(tagvalue), separator)
|
919
923
|
query = fallback.maybe_query(options)
|
920
924
|
if query
|
921
925
|
QueryExpressionNode.new(query, fallback.condition_values(options))
|
@@ -925,9 +929,9 @@ module Hotdog
|
|
925
929
|
end
|
926
930
|
end
|
927
931
|
|
928
|
-
class
|
929
|
-
def initialize(
|
930
|
-
super(
|
932
|
+
class GlobTagnameNode < GlobExpressionNode
|
933
|
+
def initialize(tagname, separator=nil)
|
934
|
+
super(tagname.to_s, nil, separator)
|
931
935
|
end
|
932
936
|
|
933
937
|
def condition(options={})
|
@@ -939,11 +943,11 @@ module Hotdog
|
|
939
943
|
end
|
940
944
|
|
941
945
|
def condition_values(options={})
|
942
|
-
[
|
946
|
+
[tagname]
|
943
947
|
end
|
944
948
|
|
945
949
|
def maybe_fallback(options={})
|
946
|
-
fallback =
|
950
|
+
fallback = GlobTagnameNode.new(to_glob(tagname), separator)
|
947
951
|
query = fallback.maybe_query(options)
|
948
952
|
if query
|
949
953
|
QueryExpressionNode.new(query, fallback.condition_values(options))
|
@@ -953,9 +957,9 @@ module Hotdog
|
|
953
957
|
end
|
954
958
|
end
|
955
959
|
|
956
|
-
class
|
957
|
-
def initialize(
|
958
|
-
super(nil,
|
960
|
+
class GlobTagvalueNode < GlobExpressionNode
|
961
|
+
def initialize(tagvalue, separator=nil)
|
962
|
+
super(nil, tagvalue.to_s, separator)
|
959
963
|
end
|
960
964
|
|
961
965
|
def condition(options={})
|
@@ -967,11 +971,11 @@ module Hotdog
|
|
967
971
|
end
|
968
972
|
|
969
973
|
def condition_values(options={})
|
970
|
-
[
|
974
|
+
[tagvalue, tagvalue]
|
971
975
|
end
|
972
976
|
|
973
977
|
def maybe_fallback(options={})
|
974
|
-
fallback =
|
978
|
+
fallback = GlobTagvalueNode.new(to_glob(tagvalue), separator)
|
975
979
|
query = fallback.maybe_query(options)
|
976
980
|
if query
|
977
981
|
QueryExpressionNode.new(query, fallback.condition_values(options))
|
@@ -982,8 +986,8 @@ module Hotdog
|
|
982
986
|
end
|
983
987
|
|
984
988
|
class GlobHostOrTagNode < GlobExpressionNode
|
985
|
-
def initialize(
|
986
|
-
super(
|
989
|
+
def initialize(tagname, separator=nil)
|
990
|
+
super(tagname.to_s, nil, separator)
|
987
991
|
end
|
988
992
|
|
989
993
|
def condition(options={})
|
@@ -995,11 +999,11 @@ module Hotdog
|
|
995
999
|
end
|
996
1000
|
|
997
1001
|
def condition_values(options={})
|
998
|
-
[
|
1002
|
+
[tagname, tagname, tagname]
|
999
1003
|
end
|
1000
1004
|
|
1001
1005
|
def maybe_fallback(options={})
|
1002
|
-
fallback = GlobHostOrTagNode.new(to_glob(
|
1006
|
+
fallback = GlobHostOrTagNode.new(to_glob(tagname), separator)
|
1003
1007
|
query = fallback.maybe_query(options)
|
1004
1008
|
if query
|
1005
1009
|
QueryExpressionNode.new(query, fallback.condition_values(options))
|
@@ -1012,21 +1016,21 @@ module Hotdog
|
|
1012
1016
|
class RegexpExpressionNode < TagExpressionNode
|
1013
1017
|
def dump(options={})
|
1014
1018
|
data = {}
|
1015
|
-
data[:
|
1019
|
+
data[:tagname_regexp] = tagname.to_s if tagname
|
1016
1020
|
data[:separator] = separator.to_s if separator
|
1017
|
-
data[:
|
1021
|
+
data[:tagvalue_regexp] = tagvalue.to_s if tagvalue
|
1018
1022
|
data[:fallback] = @fallback.dump(options) if @fallback
|
1019
1023
|
data
|
1020
1024
|
end
|
1021
1025
|
end
|
1022
1026
|
|
1023
1027
|
class RegexpHostNode < RegexpExpressionNode
|
1024
|
-
def initialize(
|
1025
|
-
case
|
1028
|
+
def initialize(tagvalue, separator=nil)
|
1029
|
+
case tagvalue
|
1026
1030
|
when /\A\/(.*)\/\z/
|
1027
|
-
|
1031
|
+
tagvalue = $1
|
1028
1032
|
end
|
1029
|
-
super("host",
|
1033
|
+
super("host", tagvalue, separator)
|
1030
1034
|
end
|
1031
1035
|
|
1032
1036
|
def condition(options={})
|
@@ -1038,21 +1042,21 @@ module Hotdog
|
|
1038
1042
|
end
|
1039
1043
|
|
1040
1044
|
def condition_values(options={})
|
1041
|
-
[
|
1045
|
+
[tagvalue]
|
1042
1046
|
end
|
1043
1047
|
end
|
1044
1048
|
|
1045
1049
|
class RegexpTagNode < RegexpExpressionNode
|
1046
|
-
def initialize(
|
1047
|
-
case
|
1050
|
+
def initialize(tagname, tagvalue, separator=nil)
|
1051
|
+
case tagname
|
1048
1052
|
when /\A\/(.*)\/\z/
|
1049
|
-
|
1053
|
+
tagname = $1
|
1050
1054
|
end
|
1051
|
-
case
|
1055
|
+
case tagvalue
|
1052
1056
|
when /\A\/(.*)\/\z/
|
1053
|
-
|
1057
|
+
tagvalue = $1
|
1054
1058
|
end
|
1055
|
-
super(
|
1059
|
+
super(tagname, tagvalue, separator)
|
1056
1060
|
end
|
1057
1061
|
|
1058
1062
|
def condition(options={})
|
@@ -1064,17 +1068,17 @@ module Hotdog
|
|
1064
1068
|
end
|
1065
1069
|
|
1066
1070
|
def condition_values(options={})
|
1067
|
-
[
|
1071
|
+
[tagname, tagvalue]
|
1068
1072
|
end
|
1069
1073
|
end
|
1070
1074
|
|
1071
|
-
class
|
1072
|
-
def initialize(
|
1073
|
-
case
|
1075
|
+
class RegexpTagnameNode < RegexpExpressionNode
|
1076
|
+
def initialize(tagname, separator=nil)
|
1077
|
+
case tagname
|
1074
1078
|
when /\A\/(.*)\/\z/
|
1075
|
-
|
1079
|
+
tagname = $1
|
1076
1080
|
end
|
1077
|
-
super(
|
1081
|
+
super(tagname.to_s, nil, separator)
|
1078
1082
|
end
|
1079
1083
|
|
1080
1084
|
def condition(options={})
|
@@ -1086,17 +1090,17 @@ module Hotdog
|
|
1086
1090
|
end
|
1087
1091
|
|
1088
1092
|
def condition_values(options={})
|
1089
|
-
[
|
1093
|
+
[tagname]
|
1090
1094
|
end
|
1091
1095
|
end
|
1092
1096
|
|
1093
|
-
class
|
1094
|
-
def initialize(
|
1095
|
-
case
|
1097
|
+
class RegexpTagvalueNode < RegexpExpressionNode
|
1098
|
+
def initialize(tagvalue, separator=nil)
|
1099
|
+
case tagvalue
|
1096
1100
|
when /\A\/(.*)\/\z/
|
1097
|
-
|
1101
|
+
tagvalue = $1
|
1098
1102
|
end
|
1099
|
-
super(nil,
|
1103
|
+
super(nil, tagvalue.to_s, separator)
|
1100
1104
|
end
|
1101
1105
|
|
1102
1106
|
def condition(options={})
|
@@ -1108,13 +1112,13 @@ module Hotdog
|
|
1108
1112
|
end
|
1109
1113
|
|
1110
1114
|
def condition_values(options={})
|
1111
|
-
[
|
1115
|
+
[tagvalue, tagvalue]
|
1112
1116
|
end
|
1113
1117
|
end
|
1114
1118
|
|
1115
1119
|
class RegexpHostOrTagNode < RegexpExpressionNode
|
1116
|
-
def initialize(
|
1117
|
-
super(
|
1120
|
+
def initialize(tagname, separator=nil)
|
1121
|
+
super(tagname, separator)
|
1118
1122
|
end
|
1119
1123
|
|
1120
1124
|
def condition(options={})
|
@@ -1126,7 +1130,7 @@ module Hotdog
|
|
1126
1130
|
end
|
1127
1131
|
|
1128
1132
|
def condition_values(options={})
|
1129
|
-
[
|
1133
|
+
[tagname, tagname, tagname]
|
1130
1134
|
end
|
1131
1135
|
end
|
1132
1136
|
end
|