appengine-paginator 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ begin
8
8
  gem.summary = %Q{A gem to assist in pagination for the Google AppEngine}
9
9
  gem.description = %Q{Pagination on JRuby running on the Google AppEngine}
10
10
  gem.email = "josh@codingforrent.com"
11
- gem.homepage = "http://github.com/joshsmoore@gmail.com/appengine-paginator"
11
+ gem.homepage = "http://github.com/joshsmoore/appengine-paginator"
12
12
  gem.authors = ["Josh Moore"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{appengine-paginator}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Josh Moore"]
12
- s.date = %q{2010-10-09}
12
+ s.date = %q{2010-10-15}
13
13
  s.description = %q{Pagination on JRuby running on the Google AppEngine}
14
14
  s.email = %q{josh@codingforrent.com}
15
15
  s.executables = ["autospec", "rackup", "spec"]
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  "spec/support/post.rb",
45
45
  "spec_runner"
46
46
  ]
47
- s.homepage = %q{http://github.com/joshsmoore@gmail.com/appengine-paginator}
47
+ s.homepage = %q{http://github.com/joshsmoore/appengine-paginator}
48
48
  s.rdoc_options = ["--charset=UTF-8"]
49
49
  s.require_paths = ["lib"]
50
50
  s.rubygems_version = %q{1.3.7}
@@ -1,3 +1,4 @@
1
+ raise StandardError.new
1
2
  require 'appengine-paginator/paginate'
2
3
  require 'appengine-paginator/cursor'
3
4
 
@@ -4,15 +4,20 @@ class Cursor
4
4
  @_cursor = cursor
5
5
  end
6
6
 
7
+ # Converts the cursor to a string encoded in base64.
7
8
  def to_s
8
9
  @_cursor.to_web_safe_string
9
10
  end
10
11
 
12
+
13
+ # Converts the cursor from a base 64 encoded string and returns the cursor object
14
+ #
15
+ # * must be a base 64 encoded cursor
11
16
  def self.parse(cursor_string)
12
17
  Cursor.new Java::comGoogleAppengineApiDatastore::Cursor.from_web_safe_string(cursor_string)
13
18
  end
14
19
 
15
-
20
+ # returns the actual Java cursor (instance of com.google.appengine.api.datastore.Cursor
16
21
  def to_java
17
22
  @_cursor
18
23
  end
@@ -1,11 +1,19 @@
1
1
  class Paginate
2
2
  attr_reader :query, :limit, :options
3
+
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)
3
9
  def initialize(query, limit, *options)
4
10
  @query = query
5
11
  @limit = limit
6
12
  @options = options.first || {}
7
13
  end
8
14
 
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).
9
17
  def result
10
18
  if options[:cursor].nil?
11
19
  @query.pquery.as_query_result_list(query.convert_options(:limit => limit)[1])
@@ -15,12 +23,16 @@ class Paginate
15
23
  end
16
24
  end
17
25
 
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
18
29
  def datamapper_result
19
30
  model = options[:model]
20
31
  dm_query =Struct.new(:repository, :fields, :reload?).new(DataMapper::repository, model.properties, false)
21
32
  result.collect {|e| model.load([Paginate.entity_to_hash(e, model.properties)], dm_query)}.flatten
22
33
  end
23
34
 
35
+ # returns the cursor (the starting position for the next page)
24
36
  def cursor
25
37
  Cursor.new result.cursor
26
38
  end
@@ -15,7 +15,7 @@ describe Paginate do
15
15
  after(:all) do
16
16
  Post.destroy
17
17
  end
18
- describe '.initialize' do
18
+ define '.initialize' do
19
19
  it 'should create an instance of the Paginate class and take two required pareters' do
20
20
  Paginate.new(1,2).should be_instance_of Paginate
21
21
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appengine-paginator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Moore
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-09 00:00:00 +08:00
18
+ date: 2010-10-15 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -72,7 +72,7 @@ files:
72
72
  - spec/support/post.rb
73
73
  - spec_runner
74
74
  has_rdoc: true
75
- homepage: http://github.com/joshsmoore@gmail.com/appengine-paginator
75
+ homepage: http://github.com/joshsmoore/appengine-paginator
76
76
  licenses: []
77
77
 
78
78
  post_install_message: