Permalink
Browse files

Added support for pagination

  • Loading branch information...
1 parent 343a293 commit 0989001f45af79dcc4f18d6b7d101e19c953fe50 @andreasronge andreasronge committed Apr 27, 2012
Showing with 35 additions and 1 deletion.
  1. +11 −0 CHANGELOG
  2. +1 −1 lib/neo4j.rb
  3. +23 −0 lib/neo4j/paginated.rb
View
@@ -1,3 +1,14 @@
+* Fix for "relationship to :all assigned twice for single instance" #178
+* Fix for callback fire more then once (also means performance increase) #172
+* Support for lucene search on array properties, #118
+* Support for creating unique entities (get_or_create) #143
+* Support for specifying has_n/has_one relationship with Strings instead of Class #160
+* Support for serializer of hash and arrays on properties #185
+* Fix for Neo4j::Rails::Relationship default property, #195
+* Added support for pagination, see the neo4j-will_paginate gem
+* Fixed Rails generators
+* Add Cypher DSL support for is_a?
+
== 2.0.0.alpha.7 / 2012-04-19
* fix for Neo4j::Config bug - did not work from rails to set the db location, closes #191
* has_n and has_one method generate class method returning the name of the relationship as a Symbol, closes #170
View
@@ -17,7 +17,7 @@
require 'neo4j/type_converters/serialize_converter'
require 'neo4j/rails/rails'
-
+require 'neo4j/paginated'
require 'orm_adapter/adapters/neo4j'
Dir["#{File.dirname(__FILE__)}/tasks/**/*.rake"].each { |ext| load ext } if defined?(Rake) && respond_to?(:namespace)
View
@@ -0,0 +1,23 @@
+module Neo4j
+
+ # The class provides the pagination based on the given source.
+ # The source must be an Enumerable implementing methods drop, first and count (or size).
+ # This can be used to paginage any Enumerable collection and
+ # provides the integration point for other gems, like will_paginate and kaminari.
+ class Paginated
+ include Enumerable
+ attr_reader :items, :total, :current_page
+
+ def initialize(items, total, current_page)
+ @items, @total, @current_page = items, total, current_page
+ end
+
+ def self.create_from(source, page, per_page)
+ partial = source.drop((page-1) * per_page).first(per_page)
+ Paginated.new(partial, source.count, page)
+ end
+
+ delegate :each, :to => :items
+ delegate :size, :[], :to => :items
+ end
+end

0 comments on commit 0989001

Please sign in to comment.