acts_as_paginable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,30 @@
1
+ .idea
2
+ .loadpath
3
+ .project
4
+ config/database.yml
5
+ config/sunspot.yml
6
+ *.log
7
+ *.out
8
+ tmp/*
9
+ nbproject/*
10
+ index/*
11
+ config/ferret_server.yml
12
+ config/erp.yml
13
+ start_server.sh
14
+ public/images/statistics/*
15
+ .DS_Store
16
+ *.DS_Store
17
+ */.DS_Store
18
+ */*/.DS_Store
19
+ .DS_STORE
20
+ *.DS_STORE
21
+ */.DS_STORE
22
+ */*/.DS_STORE
23
+ gigit
24
+ db/development.sqlite3
25
+ db/_20090313_1033.sql
26
+ db/schema.rb
27
+ solr/
28
+ solr/*
29
+ sunspot-solr.pid
30
+ rerun.txt
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Avarteq GmbH
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.textile ADDED
@@ -0,0 +1,22 @@
1
+ h1. acts_as_paginable
2
+
3
+ h2. Motivation
4
+
5
+ Use and chain scoped_by methods in conjunction with will_paginate to create a filterable and paginable record list.
6
+
7
+ h2. Requirements
8
+
9
+ * Ruby on Rails
10
+ * will_paginate
11
+
12
+ h2. Usage
13
+
14
+ acts_as_paginable(:scopes => [ :attribute1, :attribute2 ])
15
+
16
+ params = { "bills_id" => "10", "customer_id" => "3", :page => "4"}
17
+
18
+ MyModel.atq_paginate(params, 10)
19
+
20
+ Results in
21
+
22
+ MyModel.scoped_by_bills_id("10").scoped_by_customer_id("3").paginate(:page => "4", :per_page => "10")
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "acts_as_paginable"
8
+ gem.summary = "A will_paginate enhancement to automatically receive a filterable pagination method."
9
+ gem.description = "Filter records by passing params to a controller. No need to modify the model anymore."
10
+ gem.email = "fischer@avarteq.de"
11
+ gem.homepage = "http://github.com/avarteq/acts_as_paginable"
12
+ gem.authors = ["Julian Fischer"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "acts_as_paginable #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'acts_as_paginable'
@@ -0,0 +1,37 @@
1
+ module Avarteq
2
+ module Paginator
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ # +options[:scopes]+:: List with paginable scopes
11
+ def acts_as_paginable(options = {})
12
+
13
+ # Accessors for class (static) variables
14
+ cattr_accessor :paginable_scopes, :paginable_scope_prefix, :paginable_params_suffix
15
+
16
+ self.paginable_scopes = options[:scopes] || []
17
+ self.paginable_scope_prefix = options[:scope_prefix] || "scoped_by_"
18
+ self.paginable_params_suffix = options[:params_suffix] || ""
19
+ end
20
+
21
+ def atq_paginate(params, per_page)
22
+ result = self
23
+ self.paginable_scopes.each do |scope_name|
24
+ param_name = scope_name.to_s + self.paginable_params_suffix.to_s
25
+ if params[param_name] && !params[param_name].empty? then
26
+ args = params[param_name]
27
+ scope = (self.paginable_scope_prefix + scope_name.to_s ).to_sym
28
+ result = result.send(scope, args)
29
+ end
30
+ end
31
+ result.paginate(:page => params[:page], :per_page => per_page)
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ ActiveRecord::Base.send :include, Avarteq::Paginator
data/test/helper.rb ADDED
@@ -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 'acts_as_paginable'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestActsAsPaginable < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_paginable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Julian Fischer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-04-20 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Filter records by passing params to a controller. No need to modify the model anymore.
26
+ email: fischer@avarteq.de
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.textile
33
+ files:
34
+ - .gitignore
35
+ - MIT-LICENSE
36
+ - README.textile
37
+ - Rakefile
38
+ - VERSION
39
+ - init.rb
40
+ - lib/acts_as_paginable.rb
41
+ - test/helper.rb
42
+ - test/test_acts_as_paginable.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/avarteq/acts_as_paginable
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: A will_paginate enhancement to automatically receive a filterable pagination method.
71
+ test_files:
72
+ - test/helper.rb
73
+ - test/test_acts_as_paginable.rb