Class: Factbase::SyncQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/factbase/sync/sync_query.rb

Overview

Synchronized thread-safe query.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024-2025 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(origin, mutex, fb) ⇒ SyncQuery

Constructor.



17
18
19
20
21
# File 'lib/factbase/sync/sync_query.rb', line 17

def initialize(origin, mutex, fb)
  @origin = origin
  @mutex = mutex
  @fb = fb
end

Instance Method Details

#delete!(fb = @fb) ⇒ Integer

Delete all facts that match the query.



52
53
54
55
56
# File 'lib/factbase/sync/sync_query.rb', line 52

def delete!(fb = @fb)
  try_lock do
    @origin.delete!(fb)
  end
end

#each(fb = @fb, params = {}) {|Fact| ... } ⇒ Integer

Iterate facts one by one.

Yields:

  • (Fact)

    Facts one-by-one



32
33
34
35
36
37
# File 'lib/factbase/sync/sync_query.rb', line 32

def each(fb = @fb, params = {}, &)
  return to_enum(__method__, fb, params) unless block_given?
  try_lock do
    @origin.each(fb, params, &)
  end
end

#one(fb = @fb, params = {}) ⇒ String|Integer|Float|Time|Array|NilClass

Read a single value.



43
44
45
46
47
# File 'lib/factbase/sync/sync_query.rb', line 43

def one(fb = @fb, params = {})
  try_lock do
    @origin.one(fb, params)
  end
end

#to_sObject

Turn it to a string.



24
25
26
# File 'lib/factbase/sync/sync_query.rb', line 24

def to_s
  @origin.to_s
end