Class: Factbase::IndexedQuery
- Inherits:
-
Object
- Object
- Factbase::IndexedQuery
- Includes:
- Enumerable
- Defined in:
- lib/factbase/indexed/indexed_query.rb
Overview
Query with an index, a decorator of another query.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024-2026 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#delete!(fb = @fb) ⇒ Integer
Delete all facts that match the query.
-
#each(fb = @fb, params = {}) {|Fact| ... } ⇒ Integer
Iterate facts one by one.
-
#initialize(origin, idx, fb, fresh) ⇒ IndexedQuery
constructor
Constructor.
-
#one(fb = @fb, params = {}) ⇒ String|Integer|Float|Time|Array|NilClass
Read a single value.
-
#to_s ⇒ String
Print it as a string.
Constructor Details
#initialize(origin, idx, fb, fresh) ⇒ IndexedQuery
Constructor.
21 22 23 24 25 26 |
# File 'lib/factbase/indexed/indexed_query.rb', line 21 def initialize(origin, idx, fb, fresh) @origin = origin @idx = idx @fb = fb @fresh = fresh end |
Instance Method Details
#delete!(fb = @fb) ⇒ Integer
Delete all facts that match the query.
58 59 60 61 62 |
# File 'lib/factbase/indexed/indexed_query.rb', line 58 def delete!(fb = @fb) result = @origin.delete!(fb) @idx.clear result end |
#each(fb = @fb, params = {}) {|Fact| ... } ⇒ Integer
Iterate facts one by one.
38 39 40 41 42 43 44 45 |
# File 'lib/factbase/indexed/indexed_query.rb', line 38 def each(fb = @fb, params = {}) return to_enum(__method__, fb, params) unless block_given? a = @origin.each(fb, params).to_a a.each do |f| yield Factbase::IndexedFact.new(f, @idx, @fresh) end a.size end |
#one(fb = @fb, params = {}) ⇒ String|Integer|Float|Time|Array|NilClass
Read a single value.
51 52 53 |
# File 'lib/factbase/indexed/indexed_query.rb', line 51 def one(fb = @fb, params = {}) @origin.one(fb, params) end |
#to_s ⇒ String
Print it as a string.
30 31 32 |
# File 'lib/factbase/indexed/indexed_query.rb', line 30 def to_s @origin.to_s end |