Class: Hotdog::Commands::Search::TagRegexpExpressionNode
- Inherits:
-
TagExpressionNode
- Object
- ExpressionNode
- TagExpressionNode
- Hotdog::Commands::Search::TagRegexpExpressionNode
- Defined in:
- lib/hotdog/commands/search.rb
Instance Attribute Summary
Attributes inherited from TagExpressionNode
Instance Method Summary collapse
- #evaluate(environment) ⇒ Object
-
#initialize(identifier, attribute) ⇒ TagRegexpExpressionNode
constructor
A new instance of TagRegexpExpressionNode.
Methods inherited from TagExpressionNode
Constructor Details
#initialize(identifier, attribute) ⇒ TagRegexpExpressionNode
Returns a new instance of TagRegexpExpressionNode.
288 289 290 291 292 |
# File 'lib/hotdog/commands/search.rb', line 288 def initialize(identifier, attribute) identifier = identifier.sub(%r{\A/(.*)/\z}) { $1 } if identifier attribute = attribute.sub(%r{\A/(.*)/\z}) { $1 } if attribute super(identifier, attribute) end |
Instance Method Details
#evaluate(environment) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/hotdog/commands/search.rb', line 293 def evaluate(environment) if attribute? 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) REGEXP LOWER(?) AND LOWER(tags.value) REGEXP LOWER(?);\n EOS\n else\n 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) REGEXP LOWER(?) OR LOWER(tags.name) REGEXP LOWER(?) OR LOWER(tags.value) REGEXP LOWER(?);\n EOS\n end\nend\n", identifier, attribute).map { |row| row.first } |