Class: Factbase::Looged
- Inherits:
-
Object
- Object
- Factbase::Looged
- Defined in:
- lib/factbase/looged.rb
Overview
A decorator of a Factbase, that logs all operations.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
- #dup ⇒ Object
- #export ⇒ Object
- #import(bytes) ⇒ Object
-
#initialize(fb, loog) ⇒ Looged
constructor
A new instance of Looged.
- #insert ⇒ Object
- #query(query) ⇒ Object
- #size ⇒ Object
- #txn(this = self) ⇒ Object
Constructor Details
#initialize(fb, loog) ⇒ Looged
33 34 35 36 |
# File 'lib/factbase/looged.rb', line 33 def initialize(fb, loog) @fb = fb @loog = loog end |
Class Method Details
.elapsed ⇒ Object
180 181 182 183 184 |
# File 'lib/factbase/looged.rb', line 180 def self.elapsed start = Time.now yield "in #{start.ago}" end |
Instance Method Details
#dup ⇒ Object
38 39 40 |
# File 'lib/factbase/looged.rb', line 38 def dup Factbase::Looged.new(@fb.dup, @loog) end |
#export ⇒ Object
75 76 77 |
# File 'lib/factbase/looged.rb', line 75 def export @fb.export end |
#import(bytes) ⇒ Object
79 80 81 |
# File 'lib/factbase/looged.rb', line 79 def import(bytes) @fb.import(bytes) end |
#insert ⇒ Object
46 47 48 49 50 |
# File 'lib/factbase/looged.rb', line 46 def insert f = @fb.insert @loog.debug("Inserted new fact ##{@fb.size}") Fact.new(f, @loog) end |
#query(query) ⇒ Object
52 53 54 |
# File 'lib/factbase/looged.rb', line 52 def query(query) Query.new(@fb, query, @loog) end |
#size ⇒ Object
42 43 44 |
# File 'lib/factbase/looged.rb', line 42 def size @fb.size end |
#txn(this = self) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/factbase/looged.rb', line 56 def txn(this = self, &) start = Time.now id = nil rollback = false r = @fb.txn(this) do |fbt| id = fbt.object_id yield fbt rescue Factbase::Rollback => e rollback = true raise e end if rollback @loog.debug("Txn ##{id} rolled back in #{start.ago}") else @loog.debug("Txn ##{id} #{r ? 'modified' : 'didn\'t touch'} the factbase in #{start.ago}") end r end |