Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #34 from cheald/master

Replace the pagination decorator with a pagination collection to eliminate the runtime #extend, so that we aren't constantly nuking the Ruby method cache.
  • Loading branch information...
commit b67e902c3333574467a26018bd7d9fc883f01e91 2 parents 593582b + 09be79c
@jnunemaker jnunemaker authored
View
2  lib/plucky/pagination.rb
@@ -1,4 +1,4 @@
-require 'plucky/pagination/decorator'
+require 'plucky/pagination/collection'
require 'plucky/pagination/paginator'
module Plucky
View
11 lib/plucky/pagination/decorator.rb → lib/plucky/pagination/collection.rb
@@ -1,7 +1,7 @@
require 'forwardable'
module Plucky
module Pagination
- module Decorator
+ class Collection < Array
extend Forwardable
def_delegators :@paginator,
@@ -11,6 +11,15 @@ module Decorator
:skip, :limit,
:offset, :out_of_bounds?
+ def initialize(records, paginator)
+ replace records
+ @paginator = paginator
+ end
+
+ def method_missing(method, *args)
+ @query.send method, *args
+ end
+
# Public
def paginator(p=nil)
return @paginator if p.nil?
View
4 lib/plucky/query.rb
@@ -61,9 +61,7 @@ def paginate(opts={})
:skip => paginator.skip,
}).all
- docs.extend(Pagination::Decorator)
- docs.paginator(paginator)
- docs
+ Pagination::Collection.new(docs, paginator)
end
def find_each(opts={})
View
8 spec/plucky/pagination/decorator_spec.rb → spec/plucky/pagination/collection_spec.rb
@@ -1,15 +1,13 @@
require 'helper'
-describe Plucky::Pagination::Decorator do
- context "Object decorated with Decorator with paginator set" do
+describe Plucky::Pagination::Collection do
+ context "Object decorated with Collection with paginator set" do
before do
@object = [1, 2, 3, 4]
@object_id = @object.object_id
@paginator = Plucky::Pagination::Paginator.new(20, 2, 10)
- @object.extend(described_class)
- @object.paginator(@paginator)
end
- subject { @object }
+ subject { Plucky::Pagination::Collection.new(@object, @paginator) }
it "knows paginator" do
subject.paginator.should == @paginator
Please sign in to comment.
Something went wrong with that request. Please try again.