acts_as_paginable 0.1.0 → 0.3.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.
data/.gitignore CHANGED
@@ -28,3 +28,4 @@ solr/
28
28
  solr/*
29
29
  sunspot-solr.pid
30
30
  rerun.txt
31
+ pkg/*
data/CHANGELOG.textile ADDED
@@ -0,0 +1,23 @@
1
+ h1. 0.3.0
2
+
3
+ Separated scope chaining from invokation of paginate. This allows you to invoke further methods on the chained scope such as:
4
+
5
+ bc. Bill.chain_scopes(params, per_page).sum("billing_positions.amount")
6
+
7
+ So
8
+
9
+ bc. Bill.atq_paginate(params, per_page).paginate
10
+
11
+ is now defined as:
12
+
13
+ bc. chain_scopes(:page => params[:page], :per_page => per_page).paginate(:page => params[:page], :per_page => per_page)
14
+
15
+ h1. 0.2.1
16
+
17
+ * Now supports params[:order] passed to the corresponding named_scope
18
+
19
+ h1. 0.2.0
20
+
21
+ * named_scope "order" to be able to order records like this:
22
+
23
+ bc. MyClass.scoped_by_attr.order("id DESC")
data/README.textile CHANGED
@@ -11,12 +11,10 @@ h2. Requirements
11
11
 
12
12
  h2. Usage
13
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)
14
+ bc. acts_as_paginable(:scopes => [ :attribute1, :attribute2 ])
15
+ params = { "bills_id" => "10", "customer_id" => "3", :page => "4"}
16
+ MyModel.atq_paginate(params, 10)
19
17
 
20
18
  Results in
21
19
 
22
- MyModel.scoped_by_bills_id("10").scoped_by_customer_id("3").paginate(:page => "4", :per_page => "10")
20
+ bc. MyModel.scoped_by_bills_id("10").scoped_by_customer_id("3").paginate(:page => "4", :per_page => "10")
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ begin
10
10
  gem.email = "fischer@avarteq.de"
11
11
  gem.homepage = "http://github.com/avarteq/acts_as_paginable"
12
12
  gem.authors = ["Julian Fischer"]
13
+ gem.add_dependency "will_paginate"
13
14
  gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
16
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.3.0
@@ -0,0 +1,57 @@
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{acts_as_paginable}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Julian Fischer"]
12
+ s.date = %q{2010-05-17}
13
+ s.description = %q{Filter records by passing params to a controller. No need to modify the model anymore.}
14
+ s.email = %q{fischer@avarteq.de}
15
+ s.extra_rdoc_files = [
16
+ "README.textile"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "CHANGELOG.textile",
21
+ "MIT-LICENSE",
22
+ "README.textile",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "acts_as_paginable.gemspec",
26
+ "init.rb",
27
+ "lib/acts_as_paginable.rb",
28
+ "test/helper.rb",
29
+ "test/test_acts_as_paginable.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/avarteq/acts_as_paginable}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{A will_paginate enhancement to automatically receive a filterable pagination method.}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_acts_as_paginable.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<will_paginate>, [">= 0"])
47
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<will_paginate>, [">= 0"])
50
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<will_paginate>, [">= 0"])
54
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
+ end
56
+ end
57
+
@@ -3,6 +3,9 @@ module Avarteq
3
3
 
4
4
  def self.included(base)
5
5
  base.extend(ClassMethods)
6
+
7
+ # Named scope so that records can be ordered like this: MyClass.scoped_by_attr.order("id DESC")
8
+ base.send(:named_scope, :order, lambda {|order| { :order => order } })
6
9
  end
7
10
 
8
11
  module ClassMethods
@@ -16,9 +19,16 @@ module Avarteq
16
19
  self.paginable_scopes = options[:scopes] || []
17
20
  self.paginable_scope_prefix = options[:scope_prefix] || "scoped_by_"
18
21
  self.paginable_params_suffix = options[:params_suffix] || ""
19
- end
22
+ end
20
23
 
24
+ # Chains scopes as given by params and returns the paginated result.
21
25
  def atq_paginate(params, per_page)
26
+ result = chain_scopes(params, per_page)
27
+ result.paginate(:page => params[:page], :per_page => per_page)
28
+ end
29
+
30
+ # Chains scopes as given by params but does not invoke paginate.
31
+ def chain_scopes(params, per_page)
22
32
  result = self
23
33
  self.paginable_scopes.each do |scope_name|
24
34
  param_name = scope_name.to_s + self.paginable_params_suffix.to_s
@@ -28,7 +38,8 @@ module Avarteq
28
38
  result = result.send(scope, args)
29
39
  end
30
40
  end
31
- result.paginate(:page => params[:page], :per_page => per_page)
41
+ result = result.order(params[:order]) if params[:order] && !params[:order].empty?
42
+ result
32
43
  end
33
44
  end
34
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_paginable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fischer
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-20 00:00:00 +02:00
12
+ date: 2010-05-17 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: will_paginate
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: thoughtbot-shoulda
17
27
  type: :development
@@ -32,10 +42,12 @@ extra_rdoc_files:
32
42
  - README.textile
33
43
  files:
34
44
  - .gitignore
45
+ - CHANGELOG.textile
35
46
  - MIT-LICENSE
36
47
  - README.textile
37
48
  - Rakefile
38
49
  - VERSION
50
+ - acts_as_paginable.gemspec
39
51
  - init.rb
40
52
  - lib/acts_as_paginable.rb
41
53
  - test/helper.rb