class PuppetDB::Query
Attributes
sexpr[R]
Public Class Methods
[](*args)
click to toggle source
# File lib/puppetdb/query.rb, line 11 def self.[](*args) Query.new(args) end
maybe_promote(query)
click to toggle source
# File lib/puppetdb/query.rb, line 15 def self.maybe_promote(query) return Query.new(query) unless query.class == Query query end
new(query = [])
click to toggle source
# File lib/puppetdb/query.rb, line 7 def initialize(query = []) @sexpr = query end
Public Instance Methods
and(query)
click to toggle source
# File lib/puppetdb/query.rb, line 42 def and(query) compose(query) { |q| Query.new([:and, @sexpr, q.sexpr]) } end
build()
click to toggle source
# File lib/puppetdb/query.rb, line 54 def build JSON.dump(@sexpr) end
compose(query) { |query| ... }
click to toggle source
# File lib/puppetdb/query.rb, line 24 def compose(query) query = self.class.maybe_promote(query) # If an operand is the empty query ([]), compose returns a copy # of the non-empty operand. If both operands are empty, the # empty query is returned. If both operands are non-empty, the # compose continues. if query.empty? && !empty? Query.new(@sexpr) elsif empty? && !query.empty? Query.new(query.sexpr) elsif empty? && query.empty? Query.new([]) else yield query end end
empty?()
click to toggle source
# File lib/puppetdb/query.rb, line 20 def empty? @sexpr.empty? end
or(query)
click to toggle source
# File lib/puppetdb/query.rb, line 46 def or(query) compose(query) { |q| Query.new([:or, @sexpr, q.sexpr]) } end
push(query)
click to toggle source
# File lib/puppetdb/query.rb, line 50 def push(query) compose(query) { |q| Query.new(@sexpr.dup.push(q.sexpr)) } end