Class: Factbase::Tallied

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

Overview

A decorator of a Factbase, that count all operations and then returns an instance of Factbase::Churn.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2024-2025 Yegor Bugayenko

License

MIT

Defined Under Namespace

Classes: Fact, Query

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fb, churn = Factbase::Churn.new) ⇒ Tallied

Returns a new instance of Tallied.


20
21
22
23
24
# File 'lib/factbase/tallied.rb', line 20

def initialize(fb, churn = Factbase::Churn.new)
  raise 'The "fb" is nil' if fb.nil?
  @fb = fb
  @churn = churn
end

Instance Attribute Details

#churnObject (readonly)

Returns the value of attribute churn.


18
19
20
# File 'lib/factbase/tallied.rb', line 18

def churn
  @churn
end

Instance Method Details

#insertObject


28
29
30
31
32
# File 'lib/factbase/tallied.rb', line 28

def insert
  f = Fact.new(@fb.insert, @churn)
  @churn.append(1, 0, 0)
  f
end

#query(query, maps = nil) ⇒ Object


34
35
36
# File 'lib/factbase/tallied.rb', line 34

def query(query, maps = nil)
  Query.new(@fb.query(query, maps), @churn, @fb)
end

#txnObject


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

def txn
  @fb.txn do |fbt|
    yield Factbase::Tallied.new(fbt, @churn)
  end
end