appengine-paginator 0.1.3 → 0.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # Critical default settings:
2
- disable_system_gems
3
- disable_rubygems
4
- bundle_path ".gems/bundler_gems"
2
+ #disable_system_gems
3
+ #disable_rubygems
4
+ #bundle_path ".gems/bundler_gems"
5
5
 
6
6
  # List gems to bundle here:
7
7
  gem 'rspec'
@@ -1,6 +1,6 @@
1
1
  = appengine-paginator
2
2
 
3
- This is a gem that will help you to get pagination working on the Google AppEngine. It uses the AppEngien Cursor so currently you can only get the next cursor, you cannot go in reverse and get previous records. In order to do that you would need to have two queries.
3
+ This is a gem that will help you to get pagination working on the Google AppEngine. It uses the AppEngine Cursor so currently you can only get the next cursor, you cannot go in reverse and get previous records. In order to do that you would need to have two queries.
4
4
 
5
5
  == Installation
6
6
 
@@ -14,13 +14,22 @@ require 'appengine-paginator'
14
14
 
15
15
  Simply create a paginate object by passing it an AppEngine::Datastore::Query object, the limit, then an optional model and option cursor.
16
16
 
17
- i.e. p = Paginate.new(query, 10, :model => Post, :cursor => c)
17
+ i.e. p = Paginator::Paginate.new(query, 10, :model => Post, :cursor => c)
18
18
 
19
19
  The query and the limit are pretty self explanitory. The :model is an optional datamapper model that is used if you want the paginate object to return active record models. The cursor is what tells the query where to start, thus giving it pagination.
20
20
 
21
21
  Once the paginate object is created you can access the results by either calling result or datamapper_result. The result method returns the raw entities returned by the query. The datastore_result method returns an array of Datamapper models that are instiances of the the model class (the class you passed in at creating time). If a cursor is passed in then the result set will start with the record indicated by the cursor (i.e. if you passed in a limit of 10 and then created the cursor it would point to the 11th search result).
22
22
 
23
- In order to get the cursor simply call cursor on the paginate object. This will return an instance of Cursor (a wrapper for com.google.appengine.api.datastore.Cursor) which points to the first row after the given limit. Simple call to_s on the cursor object to get a string representation that can be stored in a session, the datastore, or on the rendered HTML page. Calling Cursor.parse <string_representation_of_cursor> will convert the cursor string back into a cursor object that can be passed into a new Paginate object.
23
+ In order to get the cursor simply call cursor on the paginate object. This will return an instance of Paginator::Cursor (a wrapper for com.google.appengine.api.datastore.Cursor) which points to the first row after the given limit. Simple call to_s on the cursor object to get a string representation that can be stored in a session, the datastore, or on the rendered HTML page. Calling Paginator::Cursor.parse <string_representation_of_cursor> will convert the cursor string back into a cursor object that can be passed into a new Paginator::Paginate object.
24
+
25
+ == DataMapper integration
26
+
27
+ As long as DataMapper is loaded before appengine-paginator then it will integrate into DataMapper. With datamapper integration you can pass the cursor into the query like this: p = Post.all(:limit => 10, :cursor => c, :updated_at.gt => Date.today) (where c is a Paginator::Cursor). Also all the result sets of datamapper queries now have a cursor method that will return the Paginator::Cursor that is the start of the next query. Here is a complete example:
28
+
29
+ posts = Post.all :updated_at.gt => Date.today, :limit => 10
30
+ c = posts.cursor
31
+
32
+ next_page_posts = Post.all :updated_at.gt => Date.today, :limit => 10, :cursor => c
24
33
 
25
34
  == Note on Patches/Pull Requests
26
35
 
data/Rakefile CHANGED
@@ -18,17 +18,17 @@ rescue LoadError
18
18
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
19
  end
20
20
 
21
- require 'spec/rake/spectask'
22
- Spec::Rake::SpecTask.new(:spec) do |spec|
23
- spec.libs << 'lib' << 'spec'
24
- spec.spec_files = FileList['spec/**/*_spec.rb']
25
- end
26
-
27
- Spec::Rake::SpecTask.new(:rcov) do |spec|
28
- spec.libs << 'lib' << 'spec'
29
- spec.pattern = 'spec/**/*_spec.rb'
30
- spec.rcov = true
31
- end
21
+ #require 'spec/rake/spectask'
22
+ #Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ # spec.libs << 'lib' << 'spec'
24
+ # spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ #end
26
+ #
27
+ #Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ # spec.libs << 'lib' << 'spec'
29
+ # spec.pattern = 'spec/**/*_spec.rb'
30
+ # spec.rcov = true
31
+ #end
32
32
 
33
33
  task :spec => :check_dependencies
34
34
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0.pre
@@ -1,60 +1,64 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{appengine-paginator}
8
- s.version = "0.1.3"
8
+ s.version = "0.2.0.pre"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Josh Moore"]
12
- s.date = %q{2010-10-20}
12
+ s.date = %q{2010-11-16}
13
13
  s.description = %q{Pagination on JRuby running on the Google AppEngine}
14
14
  s.email = %q{josh@codingforrent.com}
15
- s.executables = ["autospec", "rackup", "spec"]
15
+ s.executables = ["ldiff", "spec", "rspec", "rackup", "htmldiff", "autospec"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE",
18
- "README.rdoc"
18
+ "README.rdoc"
19
19
  ]
20
20
  s.files = [
21
21
  ".document",
22
- ".gitignore",
23
- "Gemfile",
24
- "LICENSE",
25
- "README.rdoc",
26
- "Rakefile",
27
- "VERSION",
28
- "WEB-INF/app.yaml",
29
- "appengine-paginator.gemspec",
30
- "bin/autospec",
31
- "bin/rackup",
32
- "bin/spec",
33
- "config.ru",
34
- "lib/appengine-paginator.rb",
35
- "lib/appengine-paginator/cursor.rb",
36
- "lib/appengine-paginator/paginate.rb",
37
- "public/favicon.ico",
38
- "public/robots.txt",
39
- "spec/appengine-paginator_spec.rb",
40
- "spec/cursor_spec.rb",
41
- "spec/paginate_spec.rb",
42
- "spec/spec.opts",
43
- "spec/spec_helper.rb",
44
- "spec/support/post.rb",
45
- "spec_runner"
22
+ "Gemfile",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "WEB-INF/app.yaml",
28
+ "appengine-paginator.gemspec",
29
+ "bin/autospec",
30
+ "bin/htmldiff",
31
+ "bin/ldiff",
32
+ "bin/rackup",
33
+ "bin/rspec",
34
+ "bin/spec",
35
+ "config.ru",
36
+ "lib/appengine-paginator.rb",
37
+ "lib/appengine-paginator/cursor.rb",
38
+ "lib/appengine-paginator/datamapper_ext.rb",
39
+ "lib/appengine-paginator/paginate.rb",
40
+ "public/favicon.ico",
41
+ "public/robots.txt",
42
+ "spec/appengine-paginator_spec.rb",
43
+ "spec/cursor_spec.rb",
44
+ "spec/datamapper_ext_spec.rb",
45
+ "spec/paginate_spec.rb",
46
+ "spec/spec.opts",
47
+ "spec/spec_helper.rb",
48
+ "spec/support/post.rb",
49
+ "spec_runner"
46
50
  ]
47
51
  s.homepage = %q{http://github.com/joshsmoore/appengine-paginator}
48
- s.rdoc_options = ["--charset=UTF-8"]
49
52
  s.require_paths = ["lib"]
50
53
  s.rubygems_version = %q{1.3.7}
51
54
  s.summary = %q{A gem to assist in pagination for the Google AppEngine}
52
55
  s.test_files = [
53
56
  "spec/appengine-paginator_spec.rb",
54
- "spec/cursor_spec.rb",
55
- "spec/paginate_spec.rb",
56
- "spec/spec_helper.rb",
57
- "spec/support/post.rb"
57
+ "spec/cursor_spec.rb",
58
+ "spec/datamapper_ext_spec.rb",
59
+ "spec/paginate_spec.rb",
60
+ "spec/spec_helper.rb",
61
+ "spec/support/post.rb"
58
62
  ]
59
63
 
60
64
  if s.respond_to? :specification_version then
@@ -62,11 +66,20 @@ Gem::Specification.new do |s|
62
66
  s.specification_version = 3
63
67
 
64
68
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
69
+ s.add_runtime_dependency(%q<rspec>, [">= 0"])
70
+ s.add_runtime_dependency(%q<dm-appengine>, [">= 0"])
71
+ s.add_runtime_dependency(%q<dm-core>, [">= 0"])
65
72
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
66
73
  else
74
+ s.add_dependency(%q<rspec>, [">= 0"])
75
+ s.add_dependency(%q<dm-appengine>, [">= 0"])
76
+ s.add_dependency(%q<dm-core>, [">= 0"])
67
77
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
68
78
  end
69
79
  else
80
+ s.add_dependency(%q<rspec>, [">= 0"])
81
+ s.add_dependency(%q<dm-appengine>, [">= 0"])
82
+ s.add_dependency(%q<dm-core>, [">= 0"])
70
83
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
71
84
  end
72
85
  end
@@ -1,3 +1,3 @@
1
- #!/Users/jmoore/.rvm/rubies/ree-1.8.7-2010.02/bin/ruby
1
+ #!/Users/joshmoore/.rvm/rubies/ree-1.8.7-2010.01/bin/ruby
2
2
  require File.expand_path(File.join(File.dirname(__FILE__), "../.gems/bundler_gems/jruby/1.8/environment"))
3
- load File.expand_path(File.join(File.dirname(__FILE__), "../.gems/bundler_gems/jruby/1.8/gems/rspec-1.3.0/bin/autospec"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../.gems/bundler_gems/jruby/1.8/gems/rspec-core-2.1.0/bin/autospec"))
@@ -0,0 +1,3 @@
1
+ #!/Users/joshmoore/.rvm/rubies/ree-1.8.7-2010.01/bin/ruby
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../.gems/bundler_gems/jruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../.gems/bundler_gems/jruby/1.8/gems/diff-lcs-1.1.2/bin/htmldiff"))
@@ -0,0 +1,3 @@
1
+ #!/Users/joshmoore/.rvm/rubies/ree-1.8.7-2010.01/bin/ruby
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../.gems/bundler_gems/jruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../.gems/bundler_gems/jruby/1.8/gems/diff-lcs-1.1.2/bin/ldiff"))
data/bin/rackup CHANGED
@@ -1,3 +1,3 @@
1
- #!/Users/jmoore/.rvm/rubies/ree-1.8.7-2010.02/bin/ruby
1
+ #!/Users/joshmoore/.rvm/rubies/ree-1.8.7-2010.01/bin/ruby
2
2
  require File.expand_path(File.join(File.dirname(__FILE__), "../.gems/bundler_gems/jruby/1.8/environment"))
3
3
  load File.expand_path(File.join(File.dirname(__FILE__), "../.gems/bundler_gems/jruby/1.8/gems/rack-1.2.1/bin/rackup"))
@@ -0,0 +1,3 @@
1
+ #!/Users/joshmoore/.rvm/rubies/ree-1.8.7-2010.01/bin/ruby
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../.gems/bundler_gems/jruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../.gems/bundler_gems/jruby/1.8/gems/rspec-core-2.1.0/bin/rspec"))
@@ -0,0 +1 @@
1
+ run lambda {Rack::Response.new('Hello').finish}
@@ -1,2 +1,3 @@
1
1
  require 'appengine-paginator/paginate'
2
- require 'appengine-paginator/cursor'
2
+ require 'appengine-paginator/cursor'
3
+ require 'appengine-paginator/datamapper_ext'
@@ -1,24 +1,27 @@
1
- class Cursor
1
+ module Paginator
2
+ class Cursor
2
3
 
3
- def initialize(cursor)
4
- @_cursor = cursor
5
- end
4
+ def initialize(cursor)
5
+ @_cursor = cursor
6
+ end
6
7
 
7
- # Converts the cursor to a string encoded in base64.
8
- def to_s
9
- @_cursor.to_web_safe_string
10
- end
8
+ # Converts the cursor to a string encoded in base64.
9
+ def to_s
10
+ @_cursor.to_web_safe_string
11
+ end
11
12
 
12
13
 
13
- # Converts the cursor from a base 64 encoded string and returns the cursor object
14
- #
15
- # * must be a base 64 encoded cursor
16
- def self.parse(cursor_string)
17
- Cursor.new Java::comGoogleAppengineApiDatastore::Cursor.from_web_safe_string(cursor_string)
18
- end
14
+ # Converts the cursor from a base 64 encoded string and returns the cursor object
15
+ #
16
+ # * must be a base 64 encoded cursor
17
+ def self.parse(cursor_string)
18
+ Cursor.new Java::comGoogleAppengineApiDatastore::Cursor.from_web_safe_string(cursor_string)
19
+ end
19
20
 
20
- # returns the actual Java cursor (instance of com.google.appengine.api.datastore.Cursor
21
- def to_java
22
- @_cursor
21
+ # returns the actual Java cursor (instance of com.google.appengine.api.datastore.Cursor
22
+ def to_java
23
+ @_cursor
24
+ end
23
25
  end
24
26
  end
27
+
@@ -0,0 +1,89 @@
1
+ datamapper = false
2
+ begin
3
+ DataMapper
4
+ datamapper = true
5
+ rescue
6
+ end
7
+
8
+ if datamapper
9
+ module DataMapper
10
+ class Query
11
+ alias :old_update :update
12
+
13
+
14
+ def update(other)
15
+
16
+ class << self;
17
+ def singleton_class;
18
+ self;
19
+ end
20
+
21
+ ;
22
+ end
23
+ @cursor = other[:cursor]
24
+
25
+ @cursor = @cursor.to_java if @cursor.instance_of? Paginator::Cursor
26
+
27
+ singleton_class.class.send :define_method, :cursor do
28
+ @cursor
29
+ end
30
+
31
+ other.delete :cursor
32
+ old_update(other)
33
+ end
34
+ end
35
+ end
36
+
37
+ module DataMapper
38
+ module Adapters
39
+ class AppEngineAdapter
40
+ class QueryBuilder
41
+ alias :old_run :run
42
+
43
+ def get_entities
44
+ if is_get?
45
+ Datastore.get(@keys)
46
+ else
47
+ prepare_java_query.collect { |e| e }
48
+ end
49
+ end
50
+
51
+ def prepare_java_query
52
+ begin
53
+ chunk_size = FetchOptions::DEFAULT_CHUNK_SIZE
54
+ options = FetchOptions::Builder.with_chunk_size(
55
+ chunk_size)
56
+ options.limit(@limit) if @limit
57
+ options.offset(@offset) if @offset
58
+ options.cursor(@dm_query.cursor) if @dm_query.respond_to?(:cursor) && @dm_query.cursor
59
+ @query.pquery.as_query_result_list(options)
60
+ rescue java.lang.IllegalArgumentException => ex
61
+ raise ArgumentError, ex.message
62
+ end
63
+ end
64
+
65
+ def run
66
+ resources = old_run
67
+
68
+ class << resources;
69
+ def singleton_class;
70
+ self.class;
71
+ end
72
+
73
+ ;
74
+ end
75
+
76
+
77
+ cursor = prepare_java_query.cursor
78
+ resources.singleton_class.send :define_method, :cursor do
79
+ Paginator::Cursor.new(cursor)
80
+ end
81
+
82
+ resources
83
+ end
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+ end
@@ -1,67 +1,69 @@
1
- class Paginate
2
- attr_reader :query, :limit, :options
1
+ module Paginator
2
+ class Paginate
3
+ attr_reader :query, :limit, :options
3
4
 
4
- # creates a paginate object
5
- # * query - an instance of AppEngine::Datastore::Query
6
- # * limit - number of items per page
7
- # * :model => DataMapperObject - used to cast the datamapper_result (optional)
8
- # * :cursor => instance of Cursor - used to skip to the next page in the query (optional)
9
- def initialize(query, limit, *options)
10
- @query = query
11
- @limit = limit
12
- @options = options.first || {}
13
- end
5
+ # creates a paginate object
6
+ # * query - an instance of AppEngine::Datastore::Query
7
+ # * limit - number of items per page
8
+ # * :model => DataMapperObject - used to cast the datamapper_result (optional)
9
+ # * :cursor => instance of Cursor - used to skip to the next page in the query (optional)
10
+ def initialize(query, limit, *options)
11
+ @query = query
12
+ @limit = limit
13
+ @options = options.first || {}
14
+ end
14
15
 
15
- # Returns an array of entities. This array is the current page based on the
16
- # position of the cursor (or the first page if no cursor is passed in).
17
- def result
18
- if options[:cursor].nil?
19
- @query.pquery.as_query_result_list(query.convert_options(:limit => limit)[1])
20
- else
21
- java_cursor = options[:cursor].instance_of?(Cursor) ? options[:cursor].to_java : options[:cursor]
22
- @query.pquery.as_query_result_list(query.convert_options(:limit => limit)[1].cursor(java_cursor))
16
+ # Returns an array of entities. This array is the current page based on the
17
+ # position of the cursor (or the first page if no cursor is passed in).
18
+ def result
19
+ if options[:cursor].nil?
20
+ @query.pquery.as_query_result_list(query.convert_options(:limit => limit)[1])
21
+ else
22
+ java_cursor = options[:cursor].instance_of?(Cursor) ? options[:cursor].to_java : options[:cursor]
23
+ @query.pquery.as_query_result_list(query.convert_options(:limit => limit)[1].cursor(java_cursor))
24
+ end
23
25
  end
24
- end
25
26
 
26
- # Returns an array of DataMapper objects. This array is the current page based on the
27
- # position of the cursor (or the first page if no cursor is passed in). In order for the
28
- # DataMapper objects to be loaded the paginate object must be crated with the :model option
29
- def datamapper_result
30
- model = options[:model]
31
- dm_query =Struct.new(:repository, :fields, :reload?).new(DataMapper::repository, model.properties, false)
32
- result.collect {|e| model.load([Paginate.entity_to_hash(e, model.properties)], dm_query)}.flatten
33
- end
27
+ # Returns an array of DataMapper objects. This array is the current page based on the
28
+ # position of the cursor (or the first page if no cursor is passed in). In order for the
29
+ # DataMapper objects to be loaded the paginate object must be crated with the :model option
30
+ def datamapper_result
31
+ model = options[:model]
32
+ dm_query =Struct.new(:repository, :fields, :reload?).new(DataMapper::repository, model.properties, false)
33
+ result.collect { |e| model.load([Paginate.entity_to_hash(e, model.properties)], dm_query) }.flatten
34
+ end
34
35
 
35
- # returns the cursor (the starting position for the next page)
36
- def cursor
37
- Cursor.new result.cursor
38
- end
36
+ # returns the cursor (the starting position for the next page)
37
+ def cursor
38
+ Cursor.new result.cursor
39
+ end
39
40
 
40
- #This should be moved to the Adapter
41
- def self.entity_to_hash(entity, properties)
42
- return if entity.nil?
43
- key = entity.get_key
44
- hash = {}
45
- properties.each do |property|
46
- name = property.field
47
- if property.key?
48
- hash[name] = if property.kind_of? DataMapper::Property::Key
49
- key
50
- elsif property.serial?
51
- key.get_id
52
- elsif property.kind_of? DataMapper::Property::String
53
- key.get_name
41
+ #This should be moved to the Adapter
42
+ def self.entity_to_hash(entity, properties)
43
+ return if entity.nil?
44
+ key = entity.get_key
45
+ hash = {}
46
+ properties.each do |property|
47
+ name = property.field
48
+ if property.key?
49
+ hash[name] = if property.kind_of? DataMapper::Property::Key
50
+ key
51
+ elsif property.serial?
52
+ key.get_id
53
+ elsif property.kind_of? DataMapper::Property::String
54
+ key.get_name
55
+ else
56
+ key
57
+ end
54
58
  else
55
- key
56
- end
57
- else
58
- value = entity.get_property(name)
59
- if property.kind_of?(DataMapper::Property::Decimal) && value
60
- value = Lexidecimal.string_to_decimal(entity.get_property(name))
59
+ value = entity.get_property(name)
60
+ if property.kind_of?(DataMapper::Property::Decimal) && value
61
+ value = Lexidecimal.string_to_decimal(entity.get_property(name))
62
+ end
63
+ hash[name] = value
61
64
  end
62
- hash[name] = value
63
65
  end
66
+ hash
64
67
  end
65
- hash
66
68
  end
67
69
  end
@@ -1,11 +1,11 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
- describe Cursor do
3
+ describe Paginator::Cursor do
4
4
 
5
5
  before(:each) do
6
6
  @cursor_string = 'E9oBJGofagR0ZXN0chcLEggKABoEUG9zdAwLEgRQb3N0GMEMDIIBAOABABQ'
7
7
  java_cursor = Java::ComGoogleAppengineApiDatastore::Cursor.from_web_safe_string(@cursor_string)
8
- @cursor = Cursor.new(java_cursor)
8
+ @cursor = Paginator::Cursor.new(java_cursor)
9
9
  end
10
10
 
11
11
  describe '#to_s' do
@@ -16,7 +16,7 @@ describe Cursor do
16
16
 
17
17
  describe '.parse' do
18
18
  it 'should return an object of class Cursor' do
19
- Cursor.parse(@cursor_string).should be_instance_of Cursor
19
+ Paginator::Cursor.parse(@cursor_string).should be_instance_of Paginator::Cursor
20
20
  end
21
21
  end
22
22
 
@@ -0,0 +1,89 @@
1
+ require 'spec/spec_helper'
2
+
3
+ require 'spec/support/post'
4
+
5
+ describe 'DataMapper Extensions' do
6
+ before(:all) do
7
+ Post.create(:title => "t1")
8
+ Post.create(:title => "t2")
9
+ Post.create(:title => "t3")
10
+ Post.create(:title => "t4")
11
+ Post.create(:title => "t5")
12
+ Post.create(:title => "t6")
13
+
14
+
15
+ @cursor_string = 'E9oBJGofagR0ZXN0chcLEggKABoEUG9zdAwLEgRQb3N0GMEMDIIBAOABABQ'
16
+ @java_cursor = Java::ComGoogleAppengineApiDatastore::Cursor.from_web_safe_string(@cursor_string)
17
+ @cursor = Paginator::Cursor.new(@java_cursor)
18
+
19
+ end
20
+
21
+ after(:all) do
22
+ Post.destroy
23
+ end
24
+
25
+ describe '#update' do
26
+ it 'should work as expected if not cursor is passed in' do
27
+ Post.all(:title.gt => 't2').count.should == 4
28
+ end
29
+
30
+ it 'should run without exception if a cursor is added' do
31
+ lambda { Post.all(:title => 't3', :cursor => '20')}.should_not raise_error
32
+ end
33
+
34
+ it 'should create a cursor method that returns the cursor' do
35
+ dm_query = DataMapper::Query.new(DataMapper::Repository.new(:default), Post, {})
36
+
37
+ dm_query.update(:cursor => @java_cursor)
38
+ dm_query.cursor.should == @java_cursor
39
+ end
40
+
41
+ it 'should convert a Paginator::Cursor to a java cursor' do
42
+ dm_query = DataMapper::Query.new(DataMapper::Repository.new(:default), Post, {})
43
+
44
+ dm_query.update(:cursor => @cursor)
45
+ dm_query.cursor.should == @java_cursor
46
+ end
47
+
48
+ end
49
+
50
+ describe 'should be able to use the cursor' do
51
+ it 'should start where the last cursor left off' do
52
+ p = Post.all(:limit => 2)
53
+ c = p.cursor
54
+ Post.all(:limit => 2, :cursor => c.to_java).collect{ |p| p.title}.should == ['t3', 't4']
55
+ end
56
+ end
57
+
58
+ describe '#cursor (on the returned array)' do
59
+ it 'should respond to cursor' do
60
+ Post.all.should respond_to(:cursor)
61
+ end
62
+
63
+ it 'should return an instance of' do
64
+ Post.all.cursor.should be_instance_of Paginator::Cursor
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+
71
+ describe 'loading without datamapper' do
72
+
73
+ it 'should load correctly if datamapper is not loaded' do
74
+ old_dm = DataMapper
75
+ #
76
+ Object.send :remove_const, :DataMapper
77
+ #
78
+ lambda { load 'lib/appengine-paginator/datamapper_ext.rb'}.should_not raise_error
79
+ #lambda { load 'lib/appengine-paginator.rb'}.should_not raise_error
80
+
81
+ DataMapper = old_dm
82
+
83
+ #require 'dm-core'
84
+ load 'lib/appengine-paginator/datamapper_ext.rb'
85
+
86
+
87
+ end
88
+
89
+ end
@@ -2,7 +2,8 @@ require 'spec/spec_helper'
2
2
 
3
3
  require 'spec/support/post'
4
4
 
5
- describe Paginate do
5
+ describe Paginator::Paginate do
6
+
6
7
  before(:all) do
7
8
  Post.create(:title => "t1")
8
9
  Post.create(:title => "t2")
@@ -15,30 +16,31 @@ describe Paginate do
15
16
  after(:all) do
16
17
  Post.destroy
17
18
  end
19
+
18
20
  define '.initialize' do
19
21
  it 'should create an instance of the Paginate class and take two required pareters' do
20
- Paginate.new(1,2).should be_instance_of Paginate
22
+ Paginator::Paginate.new(1, 2).should be_instance_of Paginator::Paginate
21
23
  end
22
24
 
23
25
  it 'should accept more parameters as a hash' do
24
- Paginate.new(1,2,:cursor => 4, :model => 4).should be_instance_of Paginate
26
+ Paginator::Paginate.new(1, 2, :cursor => 4, :model => 4).should be_instance_of Paginator::Paginate
25
27
  end
26
28
  end
27
29
 
28
30
  describe '#result' do
29
31
  it 'should return the results of the query' do
30
- paginate = Paginate.new(AppEngine::Datastore::Query.new('Posts'), 7)
32
+ paginate = Paginator::Paginate.new(AppEngine::Datastore::Query.new('Posts'), 7)
31
33
  paginate.result.count.should == 6
32
34
  end
33
35
 
34
36
  it 'should limit the results based on the limit value' do
35
- paginate = Paginate.new(AppEngine::Datastore::Query.new('Posts'), 2)
37
+ paginate = Paginator::Paginate.new(AppEngine::Datastore::Query.new('Posts'), 2)
36
38
  paginate.result.count.should == 2
37
39
  end
38
40
 
39
41
  it 'should start at the cursor when a cursor is provided' do
40
- p = Paginate.new(AppEngine::Datastore::Query.new('Posts'), 2)
41
- paginate = Paginate.new(AppEngine::Datastore::Query.new('Posts'), 2, :cursor => p.cursor)
42
+ p = Paginator::Paginate.new(AppEngine::Datastore::Query.new('Posts'), 2)
43
+ paginate = Paginator::Paginate.new(AppEngine::Datastore::Query.new('Posts'), 2, :cursor => p.cursor)
42
44
 
43
45
  paginate.result.first[:title].should == 't3'
44
46
  end
@@ -46,7 +48,7 @@ describe Paginate do
46
48
 
47
49
  describe '#datamapper_result' do
48
50
  before(:each) do
49
- @paginate = Paginate.new(AppEngine::Datastore::Query.new('Posts'), 2, :model => Post)
51
+ @paginate = Paginator::Paginate.new(AppEngine::Datastore::Query.new('Posts'), 2, :model => Post)
50
52
  end
51
53
 
52
54
  it 'should call the result method' do
@@ -63,18 +65,18 @@ describe Paginate do
63
65
  end
64
66
 
65
67
  it 'each item should be an instance of the passed in model' do
66
- @paginate.datamapper_result.each {|e| e.should be_instance_of Post}
68
+ @paginate.datamapper_result.each { |e| e.should be_instance_of Post }
67
69
  end
68
70
  end
69
71
 
70
72
  describe '#cursor' do
71
73
  it 'should return the cursor' do
72
- paginate = Paginate.new(AppEngine::Datastore::Query.new('Post'), 2, :model => Post)
74
+ paginate = Paginator::Paginate.new(AppEngine::Datastore::Query.new('Post'), 2, :model => Post)
73
75
  paginate.should respond_to :cursor
74
76
  end
75
77
  it 'should return the java cursor' do
76
- paginate = Paginate.new(AppEngine::Datastore::Query.new('Post'), 2, :model => Post)
77
- paginate.cursor.should be_instance_of Cursor
78
+ paginate = Paginator::Paginate.new(AppEngine::Datastore::Query.new('Post'), 2, :model => Post)
79
+ paginate.cursor.should be_instance_of Paginator::Cursor
78
80
  end
79
81
  end
80
82
  end
@@ -1,12 +1,14 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'appengine-paginator'
4
- require 'spec'
5
- require 'spec/autorun'
3
+ require 'rspec'
4
+ require 'rspec/autorun'
6
5
  require 'dm-core'
7
- require 'dm-appengine-adapter'
6
+ require 'appengine_adapter'
7
+ #require 'dm-appengine-adapter'
8
8
 
9
9
  DataMapper.setup(:default, "app_engine://memory")
10
- Spec::Runner.configure do |config|
10
+ DataMapper::Query
11
+ require 'appengine-paginator'
12
+ RSpec.configure do |config|
11
13
 
12
14
  end
@@ -1,16 +1,40 @@
1
1
  #!/usr/bin/env ruby
2
- require 'rubygems'
2
+ #require 'rubygems'
3
+ #
4
+ #version = ">= 0"
5
+ #
6
+ #if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
7
+ # version = $1
8
+ # ARGV.shift
9
+ #end
10
+ #
11
+ ##gem 'rspec', version
12
+ #
13
+ #rspec_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ #$LOAD_PATH.unshift(rspec_dir) unless $LOAD_PATH.include?(rspec_dir)
15
+ ##require 'spec/autorun'
16
+ #exit ::RSpec::Runner::CommandLine.run
17
+ begin
18
+ require 'rspec/autorun'
19
+ rescue LoadError
20
+ $stderr.puts <<-EOS
21
+ #{'*'*50}
22
+ Could not find 'rspec/autorun'
3
23
 
4
- version = ">= 0"
24
+ This may happen if you're using rubygems as your package manager, but it is not
25
+ being required through some mechanism before executing the rspec command.
5
26
 
6
- if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
7
- version = $1
8
- ARGV.shift
9
- end
27
+ You may need to do one of the following in your shell:
28
+
29
+ # for bash/zsh
30
+ export RUBYOPT=rubygems
10
31
 
11
- #gem 'rspec', version
32
+ # for csh, etc.
33
+ set RUBYOPT=rubygems
34
+
35
+ For background, please see http://gist.github.com/54177.
36
+ #{'*'*50}
37
+ EOS
38
+ exit(1)
39
+ end
12
40
 
13
- rspec_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(rspec_dir) unless $LOAD_PATH.include?(rspec_dir)
15
- require 'spec/autorun'
16
- exit ::Spec::Runner::CommandLine.run
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appengine-paginator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
4
+ hash: 961915988
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
8
+ - 2
9
+ - 0
10
+ - pre
11
+ version: 0.2.0.pre
11
12
  platform: ruby
12
13
  authors:
13
14
  - Josh Moore
@@ -15,13 +16,56 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-10-20 00:00:00 +08:00
19
+ date: 2010-11-16 00:00:00 +08:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
23
+ prerelease: false
24
+ type: :runtime
22
25
  name: rspec
26
+ version_requirements: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ hash: 3
32
+ segments:
33
+ - 0
34
+ version: "0"
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
23
37
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
38
+ type: :runtime
39
+ name: dm-appengine
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ requirement: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ prerelease: false
52
+ type: :runtime
53
+ name: dm-core
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirement: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ prerelease: false
66
+ type: :development
67
+ name: rspec
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
25
69
  none: false
26
70
  requirements:
27
71
  - - ">="
@@ -32,14 +76,16 @@ dependencies:
32
76
  - 2
33
77
  - 9
34
78
  version: 1.2.9
35
- type: :development
36
- version_requirements: *id001
79
+ requirement: *id004
37
80
  description: Pagination on JRuby running on the Google AppEngine
38
81
  email: josh@codingforrent.com
39
82
  executables:
40
- - autospec
41
- - rackup
83
+ - ldiff
42
84
  - spec
85
+ - rspec
86
+ - rackup
87
+ - htmldiff
88
+ - autospec
43
89
  extensions: []
44
90
 
45
91
  extra_rdoc_files:
@@ -47,7 +93,6 @@ extra_rdoc_files:
47
93
  - README.rdoc
48
94
  files:
49
95
  - .document
50
- - .gitignore
51
96
  - Gemfile
52
97
  - LICENSE
53
98
  - README.rdoc
@@ -56,16 +101,21 @@ files:
56
101
  - WEB-INF/app.yaml
57
102
  - appengine-paginator.gemspec
58
103
  - bin/autospec
104
+ - bin/htmldiff
105
+ - bin/ldiff
59
106
  - bin/rackup
107
+ - bin/rspec
60
108
  - bin/spec
61
109
  - config.ru
62
110
  - lib/appengine-paginator.rb
63
111
  - lib/appengine-paginator/cursor.rb
112
+ - lib/appengine-paginator/datamapper_ext.rb
64
113
  - lib/appengine-paginator/paginate.rb
65
114
  - public/favicon.ico
66
115
  - public/robots.txt
67
116
  - spec/appengine-paginator_spec.rb
68
117
  - spec/cursor_spec.rb
118
+ - spec/datamapper_ext_spec.rb
69
119
  - spec/paginate_spec.rb
70
120
  - spec/spec.opts
71
121
  - spec/spec_helper.rb
@@ -76,8 +126,8 @@ homepage: http://github.com/joshsmoore/appengine-paginator
76
126
  licenses: []
77
127
 
78
128
  post_install_message:
79
- rdoc_options:
80
- - --charset=UTF-8
129
+ rdoc_options: []
130
+
81
131
  require_paths:
82
132
  - lib
83
133
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -92,12 +142,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
142
  required_rubygems_version: !ruby/object:Gem::Requirement
93
143
  none: false
94
144
  requirements:
95
- - - ">="
145
+ - - ">"
96
146
  - !ruby/object:Gem::Version
97
- hash: 3
147
+ hash: 25
98
148
  segments:
99
- - 0
100
- version: "0"
149
+ - 1
150
+ - 3
151
+ - 1
152
+ version: 1.3.1
101
153
  requirements: []
102
154
 
103
155
  rubyforge_project:
@@ -108,6 +160,7 @@ summary: A gem to assist in pagination for the Google AppEngine
108
160
  test_files:
109
161
  - spec/appengine-paginator_spec.rb
110
162
  - spec/cursor_spec.rb
163
+ - spec/datamapper_ext_spec.rb
111
164
  - spec/paginate_spec.rb
112
165
  - spec/spec_helper.rb
113
166
  - spec/support/post.rb
data/.gitignore DELETED
@@ -1,26 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- .gems
17
- WEB-INF/lib
18
- WEB-INF/appengine-generated
19
- config.ru
20
-
21
- ## PROJECT::GENERAL
22
- coverage
23
- rdoc
24
- pkg
25
-
26
- ## PROJECT::SPECIFIC