lib/factbase/looged.rb in factbase-0.2.1 vs lib/factbase/looged.rb in factbase-0.3.0

- old
+ new

@@ -57,17 +57,18 @@ 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 + 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 @@ -118,13 +119,14 @@ end def one(params = {}) q = Factbase::Syntax.new(@expr).to_term.to_s r = nil - tail = Factbase::Looged.elapsed do - r = @fb.query(@expr).one(params) - end + tail = + Factbase::Looged.elapsed do + r = @fb.query(@expr).one(params) + end if r.nil? @loog.debug("Nothing found by '#{q}' #{tail}") else @loog.debug("Found #{r} (#{r.class}) by '#{q}' #{tail}") end @@ -133,27 +135,29 @@ def each(params = {}, &) q = Factbase::Syntax.new(@expr).to_term.to_s if block_given? r = nil - tail = Factbase::Looged.elapsed do - r = @fb.query(@expr).each(params, &) - end + tail = + Factbase::Looged.elapsed do + r = @fb.query(@expr).each(params, &) + end raise ".each of #{@query.class} returned #{r.class}" unless r.is_a?(Integer) if r.zero? @loog.debug("Nothing found by '#{q}' #{tail}") else @loog.debug("Found #{r} fact(s) by '#{q}' #{tail}") end r else array = [] - tail = Factbase::Looged.elapsed do - @fb.query(@expr).each(params) do |f| - array << f + tail = + Factbase::Looged.elapsed do + @fb.query(@expr).each(params) do |f| + array << f + end end - end if array.empty? @loog.debug("Nothing found by '#{q}' #{tail}") else @loog.debug("Found #{array.size} fact(s) by '#{q}' #{tail}") end @@ -162,12 +166,13 @@ end def delete! r = nil before = @fb.size - tail = Factbase::Looged.elapsed do - r = @fb.query(@expr).delete! - end + tail = + Factbase::Looged.elapsed do + r = @fb.query(@expr).delete! + end raise ".delete! of #{@query.class} returned #{r.class}" unless r.is_a?(Integer) if before.zero? @loog.debug("There were no facts, nothing deleted by '#{@expr}' #{tail}") elsif r.zero? @loog.debug("No facts out of #{before} deleted by '#{@expr}' #{tail}")