acts_as_ordinalized 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_ordinalized}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mandaryn"]
@@ -9,7 +9,7 @@ module ActsAsOrdinalized
9
9
  module ClassMethods
10
10
  # Configuration options are:
11
11
  #
12
- # * +wrapped_methods+ - specifies additional classmethods that should be wrapped with functionality (basic are find and paginate)
12
+ # * +wrapped_methods+ - specifies additional class methods that should be wrapped with functionality (basic are find and paginate)
13
13
  def acts_as_ordinalized(options = {})
14
14
  attr_accessor :ordinal_number
15
15
  wrapped_methods = ([:paginate, :find] << options[:wrapped_methods]).flatten.compact
@@ -35,15 +35,28 @@ module ActsAsOrdinalized
35
35
  end
36
36
  if collection_or_object.respond_to?(:each_with_index)
37
37
  collection_or_object.each_with_index do |item, index|
38
- item.ordinal_number = ordinal_base + index
38
+ item.ordinal_number = ordinal_base + index if item.respond_to?(:ordinal_number=)
39
39
  end
40
40
  elsif !collection_or_object.nil?
41
- collection_or_object.ordinal_number = ordinal_base
41
+ collection_or_object.ordinal_number = ordinal_base if collection_or_object.respond_to?(:ordinal_number=)
42
42
  end
43
43
  collection_or_object
44
44
  end
45
45
  end
46
46
 
47
47
  ActiveRecord::Base.class_eval { include ActsAsOrdinalized }
48
- ActiveRecord::Associations::AssociationCollection.class_eval { undef_method(:paginate) }
49
- ActiveRecord::Associations::AssociationCollection.class_eval { alias_method :method_missing, :method_missing_without_paginate }
48
+
49
+ #fix for will_paginate association collection with pagination
50
+ a = ActiveRecord::Associations
51
+ returning([ a::AssociationCollection ]) { |classes|
52
+ # detect http://dev.rubyonrails.org/changeset/9230
53
+ unless a::HasManyThroughAssociation.superclass == a::HasManyAssociation
54
+ classes << a::HasManyThroughAssociation
55
+ end
56
+ }.each do |klass|
57
+ klass.class_eval do
58
+ def paginate(*args)
59
+ ActsAsOrdinalized.ordinalize(super(*args))
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_ordinalized
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - mandaryn