objectreload-pagination 0.1.9 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/pagination.rb +0 -15
- data/lib/pagination/collection.rb +0 -10
- data/test/collection_test.rb +0 -5
- data/test/lib/view_test_process.rb +1 -1
- data/test/test_helper.rb +2 -2
- metadata +9 -5
- data/lib/action_controller/rescue_with_helper.rb +0 -16
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.11
|
data/lib/pagination.rb
CHANGED
@@ -2,9 +2,6 @@
|
|
2
2
|
require 'active_record/base_extensions'
|
3
3
|
require 'active_record/scope_extensions'
|
4
4
|
|
5
|
-
# Loads
|
6
|
-
require 'action_controller/rescue_with_helper'
|
7
|
-
|
8
5
|
# Loads internal pagination classes
|
9
6
|
require 'pagination/collection'
|
10
7
|
require 'pagination/named_scope'
|
@@ -13,15 +10,3 @@ require 'pagination/view_helpers'
|
|
13
10
|
|
14
11
|
# Loads the :paginate view helper
|
15
12
|
ActionView::Base.send :include, Pagination::ViewHelpers
|
16
|
-
|
17
|
-
# Load :rescue_with_handler - solution: https://rails.lighthouseapp.com/projects/8994/tickets/2034-exceptions-in-views-hard-to-catch
|
18
|
-
ActionController::Base.send :include, RescueWithHelper
|
19
|
-
|
20
|
-
ActionController::Base.send(:rescue_from, Pagination::InvalidPage, :with => :not_found)
|
21
|
-
|
22
|
-
def not_found
|
23
|
-
# Avoid calling '304 Not Modified'
|
24
|
-
if stale?(:etag => "invalid_page", :last_modified => DateTime.now.utc)
|
25
|
-
render_optional_error_file 404
|
26
|
-
end
|
27
|
-
end
|
@@ -1,11 +1,4 @@
|
|
1
1
|
module Pagination
|
2
|
-
class InvalidPage < ArgumentError
|
3
|
-
def initialize(page, max = 1)
|
4
|
-
super "#{page} must be greater than 0" if page < 1
|
5
|
-
super "#{page} must be less than #{max}" if page >= 1
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
2
|
class Collection < Array
|
10
3
|
attr_reader :current_page, :per_page, :total_entries, :total_pages
|
11
4
|
|
@@ -22,12 +15,9 @@ module Pagination
|
|
22
15
|
self.total_entries ||= @collection.empty? ? 0 : @collection.count(:id , :distinct => true)
|
23
16
|
end
|
24
17
|
|
25
|
-
raise InvalidPage.new(@current_page) if @current_page < 1
|
26
18
|
raise ArgumentError, "`per_page` setting cannot be less than 1 (#{@per_page} given)" if @per_page < 1
|
27
19
|
|
28
20
|
replace(already_paginated ? @collection : @collection.paginate(:limit => limit, :offset => offset))
|
29
|
-
|
30
|
-
raise InvalidPage.new(current_page, total_pages) if current_page > total_pages
|
31
21
|
end
|
32
22
|
|
33
23
|
def previous_page
|
data/test/collection_test.rb
CHANGED
@@ -49,11 +49,6 @@ class CollectionTest < Test::Unit::TestCase
|
|
49
49
|
assert_equal 4, pag_array.count
|
50
50
|
end
|
51
51
|
|
52
|
-
should "rise an error InvalidPage" do
|
53
|
-
assert_raise(Pagination::InvalidPage) { paginate_collection(@collection, -2, 2) }
|
54
|
-
assert_raise(Pagination::InvalidPage) { paginate_collection(@collection, 1000, 2) }
|
55
|
-
end
|
56
|
-
|
57
52
|
should "rise an error ArgumentError" do
|
58
53
|
assert_raise(ArgumentError) { paginate_collection(@collection, 2, -2) }
|
59
54
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: objectreload-pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 13
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
9
|
+
- 11
|
10
|
+
version: 0.1.11
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Mateusz Drozdzynski
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-12 00:00:00 +03:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -35,7 +36,6 @@ files:
|
|
35
36
|
- Rakefile
|
36
37
|
- VERSION
|
37
38
|
- init.rb
|
38
|
-
- lib/action_controller/rescue_with_helper.rb
|
39
39
|
- lib/active_record/base_extensions.rb
|
40
40
|
- lib/active_record/scope_extensions.rb
|
41
41
|
- lib/pagination.rb
|
@@ -59,23 +59,27 @@ rdoc_options:
|
|
59
59
|
require_paths:
|
60
60
|
- lib
|
61
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
62
63
|
requirements:
|
63
64
|
- - ">="
|
64
65
|
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
65
67
|
segments:
|
66
68
|
- 0
|
67
69
|
version: "0"
|
68
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
69
72
|
requirements:
|
70
73
|
- - ">="
|
71
74
|
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
72
76
|
segments:
|
73
77
|
- 0
|
74
78
|
version: "0"
|
75
79
|
requirements: []
|
76
80
|
|
77
81
|
rubyforge_project:
|
78
|
-
rubygems_version: 1.3.
|
82
|
+
rubygems_version: 1.3.7
|
79
83
|
signing_key:
|
80
84
|
specification_version: 3
|
81
85
|
summary: Simple pagination - without changes in controllers
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# When an exception happens inside a view, it is wrapped with an
|
2
|
-
# ActionView::TemplateError. The lookup for the rescue_with_handler
|
3
|
-
# then fails to find the handle for the original exception. This solution
|
4
|
-
# special cases the template error to look also at the wrapped exception
|
5
|
-
# and if there is a handler for that exception, then call it and ignore
|
6
|
-
# the wrapping.
|
7
|
-
module RescueWithHelper
|
8
|
-
def rescue_with_handler(exception)
|
9
|
-
if ((exception.class == ActionView::TemplateError) &&
|
10
|
-
(orig_exception = exception.original_exception) &&
|
11
|
-
(orig_handler = handler_for_rescue(orig_exception)))
|
12
|
-
exception = orig_exception
|
13
|
-
end
|
14
|
-
super(exception)
|
15
|
-
end
|
16
|
-
end
|