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
229 230 231 232 233 234 235 236 |
# File 'lib/hotdog/commands/search.rb', line 229 def initialize(identifier, attribute) if identifier == "host" @identifier = attribute else @identifier = identifier @attribute = attribute end end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
238 239 240 |
# File 'lib/hotdog/commands/search.rb', line 238 def attribute @attribute end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
237 238 239 |
# File 'lib/hotdog/commands/search.rb', line 237 def identifier @identifier end |
Instance Method Details
#attribute? ⇒ Boolean
239 240 241 |
# File 'lib/hotdog/commands/search.rb', line 239 def attribute? !attribute.nil? end |
#evaluate(environment) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/hotdog/commands/search.rb', line 242 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 } |