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.
20 21 22 23 24 |
# File 'lib/factbase/query_once.rb', line 20 def initialize(fb, query, maps) @fb = fb @query = query @maps = maps end |
Instance Method Details
#delete! ⇒ Integer
Delete all facts that match the query.
50 51 52 53 |
# File 'lib/factbase/query_once.rb', line 50 def delete! @fb.cache.clear @query.delete! end |
#each(params = {}) {|Fact| ... } ⇒ Integer
Iterate facts one by one.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/factbase/query_once.rb', line 30 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.
44 45 46 |
# File 'lib/factbase/query_once.rb', line 44 def one(params = {}) @query.one(params) end |