Class: Factbase::Looged::Query
- Inherits:
-
Object
- Object
- Factbase::Looged::Query
- Defined in:
- lib/factbase/looged.rb
Overview
Query decorator.
This is an internal class, it is not supposed to be instantiated directly.
Instance Method Summary collapse
- #delete! ⇒ Object
- #each ⇒ Object
-
#initialize(fb, expr, loog) ⇒ Query
constructor
A new instance of Query.
Constructor Details
#initialize(fb, expr, loog) ⇒ Query
Returns a new instance of Query.
126 127 128 129 130 |
# File 'lib/factbase/looged.rb', line 126 def initialize(fb, expr, loog) @fb = fb @expr = expr @loog = loog end |
Instance Method Details
#delete! ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/factbase/looged.rb', line 162 def delete! r = nil before = @fb.size 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}") else @loog.debug("Deleted #{r} fact(s) out of #{before} by '#{@expr}' #{tail}") end r end |
#each ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/factbase/looged.rb', line 132 def each(&) q = Factbase::Syntax.new(@expr).to_term.to_s if block_given? r = nil tail = Factbase::Looged.elapsed do r = @fb.query(@expr).each(&) 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 do |f| array << f end end if array.empty? @loog.debug("Nothing found by '#{q}' #{tail}") else @loog.debug("Found #{array.size} fact(s) by '#{q}' #{tail}") end array end end |