lib/picky/results.rb in picky-4.0.0pre1 vs lib/picky/results.rb in picky-4.0.0pre2

- old
+ new

@@ -28,37 +28,37 @@ results = new query, amount, offset, allocations results.prepare! extra_allocations results end + # This starts the actual processing. + # + # Without this, the allocations are not processed, + # and no ids are calculated. + # + def prepare! extra_allocations = nil + allocations.process! amount, offset, extra_allocations + end + # Delegates to allocations. # def ids amount = 20 allocations.ids amount end # The total results. Delegates to the allocations. # def total - @total || @total = allocations.total || 0 + @total ||= allocations.total || 0 end # Duration default is 0. # def duration @duration || 0 end - # This starts the actual processing. - # - # Without this, the allocations are not processed, - # and no ids are calculated. - # - def prepare! extra_allocations = nil - allocations.process! amount, offset, extra_allocations - end - # Returns a hash with the allocations, offset, duration and total. # def to_hash { allocations: allocations.to_result, offset: offset, @@ -67,24 +67,25 @@ end # Convert to json format. # def to_json options = {} - to_hash.to_json options + Yajl::Encoder.encode to_hash, options end + # For logging. + # + @@log_time_format = "%Y-%m-%d %H:%M:%S".freeze + def to_s + "#{log_type}|#{Time.now.strftime @@log_time_format}|#{'%8f' % duration}|#{'%-50s' % query}|#{'%8d' % total}|#{'%4d' % offset}|#{'%2d' % allocations.size}|" + end + # The first character in the blog designates what type of query it is. # # No calculated ids means: No results. # def log_type amount.zero?? :'.' : :'>' - end - - # For logging. - # - def to_s - "#{log_type}|#{Time.now.to_s(:db)}|#{'%8f' % duration}|#{'%-50s' % query}|#{'%8d' % total}|#{'%4d' % offset}|#{'%2d' % allocations.size}|" end end end \ No newline at end of file