Class: Hotdog::Commands::Search::TagGlobExpressionNode

Inherits:
TagExpressionNode show all
Defined in:
lib/hotdog/commands/search.rb

Instance Attribute Summary

Attributes inherited from TagExpressionNode

#attribute, #identifier

Instance Method Summary collapse

Methods inherited from TagExpressionNode

#attribute?, #initialize

Constructor Details

This class inherits a constructor from Hotdog::Commands::Search::TagExpressionNode

Instance Method Details

#evaluate(environment) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/hotdog/commands/search.rb', line 276

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) GLOB LOWER(?) AND LOWER(tags.value) GLOB 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) GLOB LOWER(?) OR LOWER(tags.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);\n\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 }