Class: Wackamole::Log
- Inherits:
-
Object
- Object
- Wackamole::Log
- Extended by:
- SingleForwardable
- Defined in:
- lib/wackamole/models/log.rb
Class Method Summary collapse
-
.default_page_size ⇒ Object
Pagination size.
-
.ensure_indexes! ⇒ Object
————————————————————————— Makes sure the correct indexes are set.
- .logs_cltn ⇒ Object
-
.paginate(conds, page = 1, page_size = default_page_size) ⇒ Object
————————————————————————— Fetch all logs matching the given condition.
Class Method Details
.default_page_size ⇒ Object
Pagination size
12 |
# File 'lib/wackamole/models/log.rb', line 12 def self.default_page_size() @page_size ||= 20; end |
.ensure_indexes! ⇒ Object
Makes sure the correct indexes are set
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wackamole/models/log.rb', line 28 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 |
.logs_cltn ⇒ Object
7 |
# File 'lib/wackamole/models/log.rb', line 7 def self.logs_cltn() Wackamole::Control.collection( 'logs' ); end |
.paginate(conds, page = 1, page_size = default_page_size) ⇒ Object
Fetch all logs matching the given condition
16 17 18 19 20 21 22 23 24 |
# File 'lib/wackamole/models/log.rb', line 16 def self.paginate( conds, page=1, page_size=default_page_size ) 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 |