Class: Factbase::SyncFactbase
- Inherits:
-
Object
- Object
- Factbase::SyncFactbase
- Defined in:
- lib/factbase/sync/sync_factbase.rb
Overview
A synchronous thread-safe factbase.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024-2025 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(origin, monitor = Monitor.new) ⇒ SyncFactbase
constructor
Constructor.
-
#insert ⇒ Factbase::Fact
Insert a new fact and return it.
-
#query(term, maps = nil) ⇒ Object
Create a query capable of iterating.
-
#to_term(query) ⇒ Factbase::Term
Convert a query to a term.
-
#txn {|Factbase| ... } ⇒ Factbase::Churn
Run an ACID transaction.
Constructor Details
#initialize(origin, monitor = Monitor.new) ⇒ SyncFactbase
Constructor.
21 22 23 24 |
# File 'lib/factbase/sync/sync_factbase.rb', line 21 def initialize(origin, monitor = Monitor.new) @origin = origin @monitor = monitor end |
Instance Method Details
#insert ⇒ Factbase::Fact
Insert a new fact and return it.
28 29 30 31 32 |
# File 'lib/factbase/sync/sync_factbase.rb', line 28 def insert try_lock do @origin.insert end end |
#query(term, maps = nil) ⇒ Object
Create a query capable of iterating.
44 45 46 47 48 |
# File 'lib/factbase/sync/sync_factbase.rb', line 44 def query(term, maps = nil) term = to_term(term) if term.is_a?(String) require_relative 'sync_query' Factbase::SyncQuery.new(@origin.query(term, maps), @monitor, self) end |
#to_term(query) ⇒ Factbase::Term
Convert a query to a term.
37 38 39 |
# File 'lib/factbase/sync/sync_factbase.rb', line 37 def to_term(query) @origin.to_term(query) end |
#txn {|Factbase| ... } ⇒ Factbase::Churn
Run an ACID transaction.
53 54 55 56 57 58 59 |
# File 'lib/factbase/sync/sync_factbase.rb', line 53 def txn try_lock do @origin.txn do |fbt| yield Factbase::SyncFactbase.new(fbt, @monitor) end end end |