Class: Factbase::Logged::Query
- Inherits:
-
Object
- Object
- Factbase::Logged::Query
- Defined in:
- lib/factbase/logged.rb
Overview
Query decorator.
This is an internal class, it is not supposed to be instantiated directly.
Instance Method Summary collapse
- #delete!(fb = @fb) ⇒ Object
- #each(fb = @fb, params = {}) ⇒ Object
-
#initialize(term, maps, tube, fb) ⇒ Query
constructor
A new instance of Query.
- #one(fb = @fb, params = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Method Details
#delete!(fb = @fb) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/factbase/logged.rb', line 182 def delete!(fb = @fb) r = nil mono = Process.clock_gettime(Factbase::Logged::MONO) before = @fb.size tail = Factbase::Logged.elapsed do r = @fb.query(@term, @maps).delete!(fb) end raise(StandardError, ".delete! of #{@term.class} returned #{r.class}") unless r.is_a?(Integer) if before.zero? @tube.say(mono, "There were no facts, nothing deleted by #{@term} #{tail}") elsif r.zero? @tube.say(mono, "No facts out of #{before} deleted by #{@term} #{tail}") else @tube.say(mono, "Deleted #{r} fact(s) out of #{before} by #{@term} #{tail}") end r end |
#each(fb = @fb, params = {}) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/factbase/logged.rb', line 141 def each(fb = @fb, params = {}, &) return to_enum(__method__, fb, params) unless block_given? mono = Process.clock_gettime(Factbase::Logged::MONO) r = nil qry = @fb.query(@term, @maps) tail = Factbase::Logged.elapsed do r = qry.each(fb, params, &) end unless r.is_a?(Integer) raise(StandardError, ".query(#{@termtext.inspect}).each() of #{qry.class} returned #{r.class}") end if params.is_a?(Hash) && !params.empty? q = "#{@termtext} with {#{params.map do |k, v| "#{k}=#{v}" end.join(', ')}}" end q ||= @termtext if r.zero? @tube.say(mono, "Zero/#{@fb.size} facts found by #{q} #{tail}") else @tube.say(mono, "Found #{r}/#{@fb.size} fact(s) by #{q} #{tail}") end r end |
#one(fb = @fb, params = {}) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/factbase/logged.rb', line 167 def one(fb = @fb, params = {}) mono = Process.clock_gettime(Factbase::Logged::MONO) r = nil tail = Factbase::Logged.elapsed do r = @fb.query(@term, @maps).one(fb, params) end if r.nil? @tube.say(mono, "Nothing found by '#{@termtext}' #{tail}") else @tube.say(mono, "Found #{r} (#{r.class}) by '#{@termtext}' #{tail}") end r end |
#to_s ⇒ Object
137 138 139 |
# File 'lib/factbase/logged.rb', line 137 def to_s @termtext end |