Class: Factbase::SyncQuery

Inherits:
Object
  • Object
show all
Includes:
Enumerable
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, monitor, fb) ⇒ SyncQuery

Constructor.

Parameters:

  • origin (Factbase::Query)

    Original query

  • monitor (Monitor)

    The monitor



19
20
21
22
23
# File 'lib/factbase/sync/sync_query.rb', line 19

def initialize(origin, monitor, fb)
  @origin = origin
  @monitor = monitor
  @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



54
55
56
57
58
# File 'lib/factbase/sync/sync_query.rb', line 54

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



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

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



45
46
47
48
49
# File 'lib/factbase/sync/sync_query.rb', line 45

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

#to_sObject

Turn it to a string.



26
27
28
# File 'lib/factbase/sync/sync_query.rb', line 26

def to_s
  @origin.to_s
end