Class: PuppetDB::Query
- Inherits:
-
Object
- Object
- PuppetDB::Query
- Defined in:
- lib/puppetdb/query.rb
Instance Attribute Summary collapse
-
#sexpr ⇒ Object
readonly
Returns the value of attribute sexpr.
Class Method Summary collapse
Instance Method Summary collapse
- #and(query) ⇒ Object
- #build ⇒ Object
- #compose(query) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(query = []) ⇒ Query
constructor
A new instance of Query.
- #or(query) ⇒ Object
- #push(query) ⇒ Object
Constructor Details
#initialize(query = []) ⇒ Query
Returns a new instance of Query.
7 8 9 |
# File 'lib/puppetdb/query.rb', line 7 def initialize(query = []) @sexpr = query end |
Instance Attribute Details
#sexpr ⇒ Object (readonly)
Returns the value of attribute sexpr.
5 6 7 |
# File 'lib/puppetdb/query.rb', line 5 def sexpr @sexpr end |
Class Method Details
Instance Method Details
#and(query) ⇒ Object
42 43 44 |
# File 'lib/puppetdb/query.rb', line 42 def and(query) compose(query) { |q| Query.new([:and, @sexpr, q.sexpr]) } end |
#build ⇒ Object
54 55 56 |
# File 'lib/puppetdb/query.rb', line 54 def build JSON.dump(@sexpr) end |
#compose(query) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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? ⇒ Boolean
20 21 22 |
# File 'lib/puppetdb/query.rb', line 20 def empty? @sexpr.empty? end |