Class: Factbase::IndexedQuery
- Inherits:
-
Object
- Object
- Factbase::IndexedQuery
- Defined in:
- lib/factbase/indexed/indexed_query.rb
Overview
Query with an index, a decorator of another query.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024-2025 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) ⇒ IndexedQuery
constructor
Constructor.
-
#one(fb = @fb, params = nil) ⇒ String|Integer|Float|Time|Array|NilClass
Read a single value.
-
#to_s ⇒ String
Print it as a string.
Constructor Details
permalink #initialize(origin, idx, fb) ⇒ IndexedQuery
Constructor.
18 19 20 21 22 |
# File 'lib/factbase/indexed/indexed_query.rb', line 18 def initialize(origin, idx, fb) @origin = origin @idx = idx @fb = fb end |
Instance Method Details
permalink #delete!(fb = @fb) ⇒ Integer
Delete all facts that match the query.
52 53 54 55 |
# File 'lib/factbase/indexed/indexed_query.rb', line 52 def delete!(fb = @fb) @idx.clear @origin.delete!(fb) end |
permalink #each(fb = @fb, params = {}) {|Fact| ... } ⇒ Integer
Iterate facts one by one.
34 35 36 37 38 39 |
# File 'lib/factbase/indexed/indexed_query.rb', line 34 def each(fb = @fb, params = {}) return to_enum(__method__, fb, params) unless block_given? @origin.each(fb, params).to_a.each do |f| yield Factbase::IndexedFact.new(f, @idx) end end |
permalink #one(fb = @fb, params = nil) ⇒ String|Integer|Float|Time|Array|NilClass
Read a single value.
45 46 47 |
# File 'lib/factbase/indexed/indexed_query.rb', line 45 def one(fb = @fb, params = nil) @origin.one(fb, params) end |
permalink #to_s ⇒ String
Print it as a string.
26 27 28 |
# File 'lib/factbase/indexed/indexed_query.rb', line 26 def to_s @origin.to_s end |