Class: Feta::Query
- Inherits:
-
Object
- Object
- Feta::Query
- Includes:
- Enumerable
- Defined in:
- lib/feta/query.rb
Overview
A query to the keeper server
Instance Method Summary (collapse)
-
- (Object) each {|Feta::Feature| ... }
Iterates through the result of the current query.
-
- (Query) initialize
constructor
A new instance of Query.
-
- (Object) only_actor(actor)
Queries only features where this actor is present.
-
- (Object) only_product(product)
Queries only features for these product.
-
- (Object) only_products(products)
Queries only features for these products.
-
- (String) to_xquery
Converts the query to an xpath expression.
- - (Object) with_id(id)
-
- (Object) with_role(role)
Restrict the actor's role to role.
Constructor Details
- (Query) initialize
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
- (Object) each {|Feta::Feature| ... }
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 |
- (Object) only_actor(actor)
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 |
- (Object) only_product(product)
Queries only features for these product
57 58 59 |
# File 'lib/feta/query.rb', line 57 def only_product(product) only_products([product]) end |
- (Object) only_products(products)
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 |
- (String) to_xquery
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 |
- (Object) with_id(id)
69 70 71 72 |
# File 'lib/feta/query.rb', line 69 def with_id(id) @feature_id = id self end |
- (Object) with_role(role)
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 |