Class: Hotdog::Commands::Search::TagExpressionNode
- Inherits:
-
ExpressionNode
- Object
- ExpressionNode
- Hotdog::Commands::Search::TagExpressionNode
- Defined in:
- lib/hotdog/commands/search.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Instance Method Summary collapse
- #attribute? ⇒ Boolean
- #evaluate(environment) ⇒ Object
-
#initialize(identifier, attribute) ⇒ TagExpressionNode
constructor
A new instance of TagExpressionNode.
Constructor Details
#initialize(identifier, attribute) ⇒ TagExpressionNode
210 211 212 213 |
# File 'lib/hotdog/commands/search.rb', line 210 def initialize(identifier, attribute) @identifier = identifier @attribute = attribute end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
215 216 217 |
# File 'lib/hotdog/commands/search.rb', line 215 def attribute @attribute end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
214 215 216 |
# File 'lib/hotdog/commands/search.rb', line 214 def identifier @identifier end |
Instance Method Details
#attribute? ⇒ Boolean
216 217 218 |
# File 'lib/hotdog/commands/search.rb', line 216 def attribute? !attribute.nil? end |
#evaluate(environment) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/hotdog/commands/search.rb', line 219 def evaluate(environment) if attribute? values = environment.execute(" SELECT DISTINCT hosts_tags.host_id FROM hosts_tags\n INNER JOIN tags ON hosts_tags.tag_id = tags.id\n WHERE LOWER(tags.name) = LOWER(?) AND LOWER(tags.value) = LOWER(?);\n EOS\n else\n values = environment.execute(<<-EOS, identifier, identifier, identifier).map { |row| row.first }\n SELECT DISTINCT hosts_tags.host_id FROM hosts_tags\n INNER JOIN hosts ON hosts_tags.host_id = hosts.id\n INNER JOIN tags ON hosts_tags.tag_id = tags.id\n WHERE LOWER(hosts.name) = LOWER(?) OR LOWER(tags.name) = LOWER(?) OR LOWER(tags.value) = LOWER(?);\n EOS\n end\n if not environment.fixed_string? and values.empty?\n # fallback to glob expression\n identifier_glob = identifier.gsub(/[-.\\/_]/, \"?\")\n if identifier != identifier_glob\n if attribute?\n attribute_glob = attribute.gsub(/[-.\\/:_]/, \"?\")\n environment.logger.info(\"fallback to glob expression: %s:%s\" % [identifier_glob, attribute_glob])\n else\n attribute_glob = nil\n environment.logger.info(\"fallback to glob expression: %s\" % [identifier_glob])\n end\n values = TagGlobExpressionNode.new(identifier_glob, attribute_glob).evaluate(environment)\n end\n end\n values\nend\n", identifier, attribute).map { |row| row.first } |