Class: Factbase::QueryOnce
- Inherits:
-
Object
- Object
- Factbase::QueryOnce
- Defined in:
- lib/factbase/query_once.rb
Overview
Query with a cache, a decorator of another query.
It is NOT thread-safe!
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024-2025 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#delete! ⇒ Integer
Delete all facts that match the query.
-
#each(params = {}) {|Fact| ... } ⇒ Integer
Iterate facts one by one.
-
#initialize(fb, query, maps) ⇒ QueryOnce
constructor
Constructor.
-
#one(params = {}) ⇒ Object
Read a single value.
Constructor Details
#initialize(fb, query, maps) ⇒ QueryOnce
Constructor.
37 38 39 40 41 |
# File 'lib/factbase/query_once.rb', line 37 def initialize(fb, query, maps) @fb = fb @query = query @maps = maps end |
Instance Method Details
#delete! ⇒ Integer
Delete all facts that match the query.
67 68 69 70 |
# File 'lib/factbase/query_once.rb', line 67 def delete! @fb.cache.clear @query.delete! end |
#each(params = {}) {|Fact| ... } ⇒ Integer
Iterate facts one by one.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/factbase/query_once.rb', line 47 def each(params = {}, &) unless block_given? return to_enum(__method__, params) if Factbase::Syntax.new(@fb, @query).to_term.abstract? key = [@query.to_s, @maps.object_id] before = @fb.cache[key] @fb.cache[key] = to_enum(__method__, params).to_a if before.nil? return @fb.cache[key] end @query.each(params, &) end |
#one(params = {}) ⇒ Object
Read a single value.
61 62 63 |
# File 'lib/factbase/query_once.rb', line 61 def one(params = {}) @query.one(params) end |