Class: Factbase::Pre

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

Overview

A decorator of a Factbase, that runs a provided block on every insert.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(fb, &block) ⇒ Pre

Returns a new instance of Pre.



34
35
36
37
38
# File 'lib/factbase/pre.rb', line 34

def initialize(fb, &block)
  raise 'The "fb" is nil' if fb.nil?
  @fb = fb
  @block = block
end

Instance Method Details

#dupObject



40
41
42
# File 'lib/factbase/pre.rb', line 40

def dup
  Factbase::Pre.new(@fb.dup, &@block)
end

#insertObject



44
45
46
47
48
# File 'lib/factbase/pre.rb', line 44

def insert
  f = @fb.insert
  @block.call(f)
  f
end

#txn(this = self) ⇒ Object



50
51
52
# File 'lib/factbase/pre.rb', line 50

def txn(this = self, &)
  @fb.txn(this, &)
end