Sha256: 4d4206251e576c433457cfabb0ea205a9d8d0b108240bdf9818812f206491648
Contents?: true
Size: 1.65 KB
Versions: 1
Compression:
Stored size: 1.65 KB
Contents
require 'forwardable' module Wackamole class Log extend ::SingleForwardable def self.logs_cltn() Wackamole::Control.collection( 'logs' ); end def_delegators :logs_cltn, :find, :find_one # Pagination size def self.default_page_size() @page_size ||= 20; end # --------------------------------------------------------------------------- # Fetch all logs matching the given condition def self.paginate( conds, page=1, page_size=default_page_size ) puts conds.inspect matching = logs_cltn.find( conds ) WillPaginate::Collection.create( page, page_size, matching.count ) do |pager| pager.replace( logs_cltn.find( conds, :sort => [ ['did', 'desc'], ['tid', 'desc'] ], :skip => (page-1)*page_size, :limit => page_size ).to_a ) end end # --------------------------------------------------------------------------- # Makes sure the correct indexes are set def self.ensure_indexes! indexes = logs_cltn.index_information created_count = 0 [:typ, :fid].each do |name| unless indexes.has_key?( "#{name}_1" ) logs_cltn.create_index( name ) created_count += 1 end end unless indexes.key?( "did_-1_tid_-1_type_-1" ) logs_cltn.create_index( [[:did, Mongo::DESCENDING], [:tid, Mongo::DESCENDING], [:type, Mongo::DESCENDING] ] ) end unless indexes.key?( "fid_-1_did_-1" ) logs_cltn.create_index( [[:fid, Mongo::DESCENDING], [:did, Mongo::DESCENDING], [:type, Mongo::DESCENDING] ] ) end created_count end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wackamole-0.0.9 | lib/wackamole/models/log.rb |