Class: Factbase::SyncQuery

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

Overview

Synchronized thread-safe query.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2024-2025 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(origin, mutex, fb) ⇒ SyncQuery

Constructor.

Parameters:


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.

Parameters:

  • fb (Factbase) (defaults to: @fb)

    The factbase

Returns:

  • (Integer)

    Total number of facts deleted


47
48
49
50
51
# File 'lib/factbase/sync/sync_query.rb', line 47

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

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

Iterate facts one by one.

Parameters:

  • params (Hash) (defaults to: {})

    Optional params accessible in the query via the “$” symbol

Yields:

  • (Fact)

    Facts one-by-one

Returns:

  • (Integer)

    Total number of facts yielded


27
28
29
30
31
32
# File 'lib/factbase/sync/sync_query.rb', line 27

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.

Parameters:

  • fb (Factbase) (defaults to: @fb)

    The factbase

  • params (Hash) (defaults to: {})

    Optional params accessible in the query via the “$” symbol

Returns:

  • (String|Integer|Float|Time|Array|NilClass)

    The value evaluated


38
39
40
41
42
# File 'lib/factbase/sync/sync_query.rb', line 38

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