dm-is-pageable 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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
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
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ryan Evans
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.
@@ -0,0 +1,17 @@
1
+ = dm-is-pageable
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Ryan Evans. See LICENSE for details.
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "dm-is-pageable"
8
+ gem.summary = %Q{Adds pagination support to DataMapper models (compatible with will_paginate)}
9
+ gem.description = %Q{Adds pagination support to DataMapper models (compatible with will_paginate)}
10
+ gem.email = "rs3vans@gmail.com"
11
+ gem.homepage = "http://github.com/rs3vans/dm-is-pageable"
12
+ gem.authors = ["Ryan Evans"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.add_dependency 'dm-core'
15
+ gem.add_dependency 'dm-aggregates'
16
+ gem.add_dependency 'activesupport'
17
+ gem.add_dependency 'will_paginate'
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'lib' << 'test'
28
+ test.pattern = 'test/**/test_*.rb'
29
+ test.verbose = true
30
+ end
31
+
32
+ begin
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'test'
36
+ test.pattern = 'test/**/test_*.rb'
37
+ test.verbose = true
38
+ end
39
+ rescue LoadError
40
+ task :rcov do
41
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
42
+ end
43
+ end
44
+
45
+ task :test => :check_dependencies
46
+
47
+ task :default => :test
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "dm-is-pageable #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dm-is-pageable}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ryan Evans"]
12
+ s.date = %q{2010-05-31}
13
+ s.description = %q{Adds pagination support to DataMapper models (compatible with will_paginate)}
14
+ s.email = %q{rs3vans@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "dm-is-pageable.gemspec",
27
+ "lib/dm-is-pageable.rb",
28
+ "lib/dm-is-pageable/is/class_methods.rb",
29
+ "lib/dm-is-pageable/is/pageable.rb",
30
+ "test/helper.rb",
31
+ "test/model.rb",
32
+ "test/test_dm-is-pageable.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/rs3vans/dm-is-pageable}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.6}
38
+ s.summary = %q{Adds pagination support to DataMapper models (compatible with will_paginate)}
39
+ s.test_files = [
40
+ "test/model.rb",
41
+ "test/helper.rb",
42
+ "test/test_dm-is-pageable.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ s.add_runtime_dependency(%q<dm-core>, [">= 0"])
52
+ s.add_runtime_dependency(%q<dm-aggregates>, [">= 0"])
53
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
54
+ s.add_runtime_dependency(%q<will_paginate>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
+ s.add_dependency(%q<dm-core>, [">= 0"])
58
+ s.add_dependency(%q<dm-aggregates>, [">= 0"])
59
+ s.add_dependency(%q<activesupport>, [">= 0"])
60
+ s.add_dependency(%q<will_paginate>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
64
+ s.add_dependency(%q<dm-core>, [">= 0"])
65
+ s.add_dependency(%q<dm-aggregates>, [">= 0"])
66
+ s.add_dependency(%q<activesupport>, [">= 0"])
67
+ s.add_dependency(%q<will_paginate>, [">= 0"])
68
+ end
69
+ end
70
+
@@ -0,0 +1,9 @@
1
+ require 'pathname'
2
+ require 'dm-core'
3
+ require 'dm-aggregates'
4
+ require 'active_support'
5
+ require 'will_paginate'
6
+
7
+ require Pathname(__FILE__).dirname.expand_path / 'dm-is-pageable' / 'is' / 'pageable'
8
+
9
+ DataMapper::Model.append_extensions DataMapper::Is::Pageable
@@ -0,0 +1,26 @@
1
+ module DataMapper
2
+ module Is
3
+ module Pageable
4
+ module ClassMethods
5
+
6
+ def paginate(opts = {})
7
+ page = opts.delete(:page) || 1
8
+ per_page = opts.delete(:per_page) || pageable_options[:per_page]
9
+ WillPaginate::Collection.create(page, per_page) do |pager|
10
+ find_opts = pageable_options[:dm_options].merge(opts)
11
+ results = all(find_opts.merge(:offset => pager.offset, :limit => pager.per_page))
12
+ pager.replace results
13
+ pager.total_entries = count(find_opts) unless pager.total_entries
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def pageable_options
20
+ class_variable_get(:@@dm_is_pageable_options)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ require Pathname(__FILE__).dirname.expand_path / 'class_methods'
2
+
3
+ module DataMapper
4
+ module Is
5
+ module Pageable
6
+
7
+ def is_pageable(opts = {})
8
+ class_variable_set(:@@dm_is_pageable_options, {})
9
+
10
+ extend ClassMethods
11
+
12
+ pageable_options[:per_page] = opts.delete(:per_page) || 10
13
+ pageable_options[:dm_options] = opts
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'dm-is-pageable'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,8 @@
1
+ class Model
2
+ include DataMapper::Resource
3
+
4
+ property :id, Serial
5
+ property :rank, Integer, :default => 0
6
+
7
+ is :pageable, :per_page => 5, :order => :rank.desc
8
+ end
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+
3
+ DataMapper::Logger.new($stdout, :debug)
4
+ DataMapper.setup(:default, 'sqlite3::memory:')
5
+
6
+ require 'model'
7
+
8
+ DataMapper.auto_migrate!
9
+
10
+ class TestDmIsPageable < Test::Unit::TestCase
11
+
12
+ context 'With Model...' do
13
+ setup do
14
+ (0..24).each do |i|
15
+ Model.create :rank => i
16
+ end
17
+ @ms = Model.paginate
18
+ end
19
+
20
+ should 'return true if paginate tests pass' do
21
+ #flunk 'bad page number' unless @ms.page == 1
22
+ flunk "bad number of pages (#{@ms.total_pages})" unless @ms.total_pages == 5
23
+ end
24
+ end
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-is-pageable
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Ryan Evans
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-31 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: dm-core
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: dm-aggregates
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :runtime
55
+ version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ name: activesupport
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :runtime
67
+ version_requirements: *id004
68
+ - !ruby/object:Gem::Dependency
69
+ name: will_paginate
70
+ prerelease: false
71
+ requirement: &id005 !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ type: :runtime
79
+ version_requirements: *id005
80
+ description: Adds pagination support to DataMapper models (compatible with will_paginate)
81
+ email: rs3vans@gmail.com
82
+ executables: []
83
+
84
+ extensions: []
85
+
86
+ extra_rdoc_files:
87
+ - LICENSE
88
+ - README.rdoc
89
+ files:
90
+ - .document
91
+ - .gitignore
92
+ - LICENSE
93
+ - README.rdoc
94
+ - Rakefile
95
+ - VERSION
96
+ - dm-is-pageable.gemspec
97
+ - lib/dm-is-pageable.rb
98
+ - lib/dm-is-pageable/is/class_methods.rb
99
+ - lib/dm-is-pageable/is/pageable.rb
100
+ - test/helper.rb
101
+ - test/model.rb
102
+ - test/test_dm-is-pageable.rb
103
+ has_rdoc: true
104
+ homepage: http://github.com/rs3vans/dm-is-pageable
105
+ licenses: []
106
+
107
+ post_install_message:
108
+ rdoc_options:
109
+ - --charset=UTF-8
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ requirements: []
127
+
128
+ rubyforge_project:
129
+ rubygems_version: 1.3.6
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Adds pagination support to DataMapper models (compatible with will_paginate)
133
+ test_files:
134
+ - test/model.rb
135
+ - test/helper.rb
136
+ - test/test_dm-is-pageable.rb