Permalink
Browse files

Sequel is back

  • Loading branch information...
1 parent 4ced819 commit fb36491eb5d17f264fb07825913e7a6d7f2952fc @mislav committed Jul 27, 2011
Showing with 33 additions and 29 deletions.
  1. +1 −1 Gemfile
  2. +2 −2 Gemfile.lock
  3. +0 −23 lib/will_paginate/finders/sequel.rb
  4. +29 −0 lib/will_paginate/sequel.rb
  5. +1 −3 spec/finders/sequel_spec.rb
View
2 Gemfile
@@ -7,7 +7,7 @@ gem 'rake'
gem 'activerecord', '~> 3.1.0.rc'
gem 'activeresource', '~> 3.1.0.rc'
gem 'actionpack', '~> 3.1.0.rc'
-gem 'sequel', '~> 3.8.0', :platforms => :ruby_18 # broken on 1.9
+gem 'sequel', '~> 3.8'
gem 'rspec', '~> 2.6.0'
gem 'mocha', '~> 0.9.8'
gem 'sqlite3', '~> 1.3.3'
View
4 Gemfile.lock
@@ -92,7 +92,7 @@ GEM
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
- sequel (3.8.0)
+ sequel (3.25.0)
sprockets (2.0.0.beta.12)
hike (~> 1.2)
rack (~> 1.0)
@@ -119,5 +119,5 @@ DEPENDENCIES
rspec (~> 2.6.0)
ruby-debug
ruby-debug19
- sequel (~> 3.8.0)
+ sequel (~> 3.8)
sqlite3 (~> 1.3.3)
View
23 lib/will_paginate/finders/sequel.rb
@@ -1,23 +0,0 @@
-require 'will_paginate/core_ext'
-require 'sequel'
-require 'sequel/extensions/pagination'
-
-existing_methods = Sequel::Dataset::Pagination.instance_methods
-
-Sequel::Dataset::Pagination.module_eval do
- # it should quack like a WillPaginate::Collection
-
- alias :total_pages :page_count unless existing_methods.include_method? :total_pages
- alias :per_page :page_size unless existing_methods.include_method? :per_page
- alias :previous_page :prev_page unless existing_methods.include_method? :previous_page
- alias :total_entries :pagination_record_count unless existing_methods.include_method? :total_entries
-
- def out_of_bounds?
- current_page > total_pages
- end
-
- # Current offset of the paginated collection
- def offset
- (current_page - 1) * per_page
- end
-end
View
29 lib/will_paginate/sequel.rb
@@ -0,0 +1,29 @@
+require 'sequel'
+require 'sequel/extensions/pagination'
+
+module WillPaginate
+ module SequelMethods
+ def total_pages
+ page_count
+ end
+
+ def per_page
+ page_size
+ end
+
+ def total_entries
+ pagination_record_count
+ end
+
+ def out_of_bounds?
+ current_page > total_pages
+ end
+
+ # Current offset of the paginated collection
+ def offset
+ (current_page - 1) * per_page
+ end
+ end
+
+ Sequel::Dataset::Pagination.send(:include, SequelMethods)
+end
View
4 spec/finders/sequel_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
begin
- require 'will_paginate/finders/sequel'
+ require 'will_paginate/sequel'
require File.expand_path('../sequel_test_connector', __FILE__)
rescue LoadError, ArgumentError => error
warn "Error running Sequel specs: #{error.message}"
@@ -37,8 +37,6 @@ class Car < Sequel::Model
result.total_pages.should == 2
result.per_page.should == 2
result.current_page.should == 1
- result.previous_page.should be_nil
- result.next_page.should == 2
end
it "should perform" do

0 comments on commit fb36491

Please sign in to comment.