Class: Feta::Query
Overview
A query to the keeper server
Instance Method Summary collapse
-
#each {|Feta::Feature| ... } ⇒ Object
Iterates through the result of the current query.
-
#initialize ⇒ Query
constructor
A new instance of Query.
-
#only_actor(actor) ⇒ Object
Queries only features where this actor is present.
-
#only_product(product) ⇒ Object
Queries only features for these product.
-
#only_products(products) ⇒ Object
Queries only features for these products.
-
#to_xquery ⇒ String
Converts the query to an xpath expression.
- #with_id(id) ⇒ Object
-
#with_role(role) ⇒ Object
Restrict the actor’s role to
role
.
Constructor Details
#initialize ⇒ Query
Returns a new instance of Query.
34 35 36 37 38 39 |
# File 'lib/feta/query.rb', line 34 def initialize @products = [] @actor = nil @role = nil @feature_id = nil end |
Instance Method Details
#each {|Feta::Feature| ... } ⇒ Object
Note:
Requires Feta.client to be set
Iterates through the result of the current query.
92 93 94 95 96 |
# File 'lib/feta/query.rb', line 92 def each ret = Feta.client.search(self) return ret.each if not block_given? ret.each { |feature| yield feature } end |
#only_actor(actor) ⇒ Object
Queries only features where this actor is present
43 44 45 46 |
# File 'lib/feta/query.rb', line 43 def only_actor(actor) @actor = actor self end |
#only_product(product) ⇒ Object
Queries only features for these product
57 58 59 |
# File 'lib/feta/query.rb', line 57 def only_product(product) only_products([product]) end |
#only_products(products) ⇒ Object
Queries only features for these products
63 64 65 66 67 |
# File 'lib/feta/query.rb', line 63 def only_products(products) @products = [] @products = products.flatten self end |
#to_xquery ⇒ String
Converts the query to an xpath expression
77 78 79 80 81 82 83 84 85 |
# File 'lib/feta/query.rb', line 77 def to_xquery id_query = @feature_id ? "@k:id=#{@feature_id}" : "" role_query = @role ? " and role='#{@role}'" : "" actor_query = @actor ? "actor[person/email='#{@actor}'#{role_query}]" : "" prods = @products.collect {|p| "product/name='#{p}'"}.join(" or ") product_query = (!@products.empty?) ? "productcontext[#{prods}]" : "" conditions = [id_query, actor_query, product_query].reject{ |x| x.empty? }.join(' and ') query = "/feature[#{conditions}]" end |
#with_id(id) ⇒ Object
69 70 71 72 |
# File 'lib/feta/query.rb', line 69 def with_id(id) @feature_id = id self end |
#with_role(role) ⇒ Object
Restrict the actor’s role to role
50 51 52 53 |
# File 'lib/feta/query.rb', line 50 def with_role(role) @role = role self end |