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
Returns a new instance of TagExpressionNode.
204 205 206 207 |
# File 'lib/hotdog/commands/search.rb', line 204 def initialize(identifier, attribute) @identifier = identifier @attribute = attribute end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
209 210 211 |
# File 'lib/hotdog/commands/search.rb', line 209 def attribute @attribute end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
208 209 210 |
# File 'lib/hotdog/commands/search.rb', line 208 def identifier @identifier end |
Instance Method Details
#attribute? ⇒ Boolean
210 211 212 |
# File 'lib/hotdog/commands/search.rb', line 210 def attribute? !attribute.nil? end |
#evaluate(environment) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/hotdog/commands/search.rb', line 213 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) = LOWER(?) AND LOWER(tags.value) = 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) = LOWER(?) OR LOWER(tags.name) = LOWER(?) OR LOWER(tags.value) = LOWER(?);\n EOS\n end\nend\n", identifier, attribute).map { |row| row.first } |