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
#initialize(term, maps, tube, fb) ⇒ Query
Returns a new instance of Query.
127 128 129 130 131 132 |
# File 'lib/factbase/logged.rb', line 127 def initialize(term, maps, tube, fb) @term = term @maps = maps @tube = tube @fb = fb end |
Instance Method Details
#delete!(fb = @fb) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/factbase/logged.rb', line 174 def delete!(fb = @fb) r = nil start = Time.now before = @fb.size tail = Factbase::Logged.elapsed do r = @fb.query(@term, @maps).delete!(fb) end raise ".delete! of #{@term.class} returned #{r.class}" unless r.is_a?(Integer) if before.zero? @tube.say(start, "There were no facts, nothing deleted by #{@term} #{tail}") elsif r.zero? @tube.say(start, "No facts out of #{before} deleted by #{@term} #{tail}") else @tube.say(start, "Deleted #{r} fact(s) out of #{before} by #{@term} #{tail}") end r end |
#each(fb = @fb, params = {}) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/factbase/logged.rb', line 138 def each(fb = @fb, params = {}, &) return to_enum(__method__, fb, params) unless block_given? start = Time.now r = nil qry = @fb.query(@term, @maps) tail = Factbase::Logged.elapsed do r = qry.each(fb, params, &) end raise ".query(#{@term.to_s.inspect}).each() of #{qry.class} returned #{r.class}" unless r.is_a?(Integer) q = Factbase::Syntax.new(@term).to_term.to_s q = "#{q} with {#{params.map { |k, v| "#{k}=#{v}" }.join(', ')}}" if params.is_a?(Hash) && !params.empty? if r.zero? @tube.say(start, "Zero/#{@fb.size} facts found by #{q} #{tail}") else @tube.say(start, "Found #{r}/#{@fb.size} fact(s) by #{q} #{tail}") end r end |
#one(fb = @fb, params = {}) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/factbase/logged.rb', line 158 def one(fb = @fb, params = {}) start = Time.now q = Factbase::Syntax.new(@term).to_term.to_s r = nil tail = Factbase::Logged.elapsed do r = @fb.query(@term, @maps).one(fb, params) end if r.nil? @tube.say(start, "Nothing found by '#{q}' #{tail}") else @tube.say(start, "Found #{r} (#{r.class}) by '#{q}' #{tail}") end r end |
#to_s ⇒ Object
134 135 136 |
# File 'lib/factbase/logged.rb', line 134 def to_s @term.to_s end |