page_adams 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 469e57128393113fb99819c0f749211948e46b4e
4
+ data.tar.gz: 4cbf476bb2960d604e3ed7deeab5c1accc4322d9
5
+ SHA512:
6
+ metadata.gz: b64d1392ce5006b58c74bca6888530a8cf4c279594269a096d4a7438c8139349e36600f3cc8ba178019d386d8489357de030f14b4e0b247846e7bb33e7e267d7
7
+ data.tar.gz: dda424b5b5f571665b731cbee4a74fac09645137ad76cc7e65a3ec9550b476f8426ab17a0149c1f5bb5e7e6adf5cae7a80ac758d889d0ac01154753690f8e1f4
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Sebastián González
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # PageAdams
2
+ ActiveRecord model pagination made easy.
3
+
4
+ ## Usage
5
+ Include PageAdams in every model you want to paginate
6
+ ~~~ruby
7
+ class Article < ApplicationRecord
8
+ include PageAdams
9
+ end
10
+ ~~~
11
+
12
+ That's it. Now you can call `Article.page 5` to get the fifth page of paginated results.
13
+
14
+ `page` returns a hash of the following structure:
15
+ ~~~ruby
16
+ > Article.page 0
17
+ => {:records=>#<ActiveRecord::Relation [#<Article id: 1>]>, :current_page=>1, :total_pages=>4}
18
+ ~~~
19
+
20
+ in wich
21
+ * the `:records` key holds an array of instances (or empty) (`ActiveRecord::Relation`)
22
+ * the `:current_page` key holds the current retrieved page (`Integer`)
23
+ * the `:total_pages` key holds the total number of instances pages (`Integer`)
24
+
25
+ ## Installation
26
+ Add this line to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem 'page_adams'
30
+ ```
31
+
32
+ And then execute:
33
+ ```bash
34
+ $ bundle install
35
+ ```
36
+
37
+ Or install it yourself as:
38
+ ```bash
39
+ $ gem install page_adams
40
+ ```
41
+
42
+ ## Tests
43
+ A basic suite of tests has been included into the gem, using RSpec.
44
+ Clone the project, enter the folder and run `rspec`.
45
+
46
+ ## License
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'PageAdams'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
data/lib/page_adams.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "page_adams/engine"
2
+
3
+ module PageAdams
4
+ mattr_accessor :page_size
5
+ @@page_size = 10
6
+
7
+ def self.setup
8
+ yield self
9
+ end
10
+
11
+ def self.included klass
12
+ klass.extend ClassMethods
13
+ end
14
+
15
+ module ClassMethods
16
+ def page page, page_size = 10
17
+ page = 1 if page.nil? or not page.is_a? Integer or page <= 0
18
+ total_records = self.count
19
+ # page_size = 10
20
+ total_pages = ((total_records % page_size) == 0) ? total_records / page_size : total_records / page_size + 1
21
+ records = self.offset(page_size * (page - 1)).limit(page_size)
22
+ { records: records, current_page: page, total_pages: total_pages }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ module PageAdams
2
+ class Engine < ::Rails::Engine
3
+ config.generators do |g|
4
+ g.test_framework :rspec
5
+ g.fixture_replacement :factory_girl
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module PageAdams
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: page_adams
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastián González
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_girl_rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faker
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ description: Automatically paginate your ActiveRecord models.
84
+ email:
85
+ - sebagonz91@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - MIT-LICENSE
91
+ - README.md
92
+ - Rakefile
93
+ - lib/page_adams.rb
94
+ - lib/page_adams/engine.rb
95
+ - lib/page_adams/version.rb
96
+ homepage: https://github.com/sebastialonso/page_adams
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.6.8
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Pagination made easy.
120
+ test_files: []