Class: Hotdog::Commands::Search::TagGlobExpressionNode
- Inherits:
-
TagExpressionNode
- Object
- ExpressionNode
- TagExpressionNode
- Hotdog::Commands::Search::TagGlobExpressionNode
- Defined in:
- lib/hotdog/commands/search.rb
Instance Attribute Summary
Attributes inherited from TagExpressionNode
Instance Method Summary collapse
Methods inherited from TagExpressionNode
#attribute?, #identifier?, #initialize
Constructor Details
This class inherits a constructor from Hotdog::Commands::Search::TagExpressionNode
Instance Method Details
#evaluate(environment) ⇒ Object
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/hotdog/commands/search.rb', line 322 def evaluate(environment) if identifier? if attribute? case identifier when /\Ahost\z/i values = environment.execute(" SELECT hosts.id FROM hosts\n WHERE LOWER(hosts.name) GLOB LOWER(?);\n EOS\n else\n values = environment.execute(<<-EOS, identifier, attribute).map { |row| row.first }\n 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) GLOB LOWER(?) AND LOWER(tags.value) GLOB LOWER(?);\n EOS\n end\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) GLOB LOWER(?) OR LOWER(tags.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);\n EOS\n end\n else\n if attribute?\n values = environment.execute(<<-EOS, attribute).map { |row| row.first }\n SELECT DISTINCT hosts_tags.host_id FROM hosts_tags\n INNER JOIN tags ON hosts_tags.tag_id = tags.id\n WHERE LOWER(tags.value) GLOB LOWER(?);\n EOS\n else\n values = []\n end\n end\n if not environment.fixed_string? and values.empty?\n # fallback to glob expression\n identifier_glob = identifier.gsub(/[-.\\/_]/, \"?\") if identifier?\n attribute_glob = attribute.gsub(/[-.\\/:_]/, \"?\") if attribute?\n if (identifier? and identifier != identifier_glob) or (attribute? and attribute != attribute_glob)\n environment.logger.info(\"fallback to glob expression: %s:%s\" % [identifier_glob, attribute_glob])\n values = TagGlobExpressionNode.new(identifier_glob, attribute_glob).evaluate(environment)\n end\n end\n values\nend\n", attribute).map { |row| row.first } |