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 +1 -1
- data/acts_as_ordinalized.gemspec +1 -1
- data/lib/acts_as_ordinalized.rb +18 -5
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/acts_as_ordinalized.gemspec
CHANGED
data/lib/acts_as_ordinalized.rb
CHANGED
@@ -9,7 +9,7 @@ module ActsAsOrdinalized
|
|
9
9
|
module ClassMethods
|
10
10
|
# Configuration options are:
|
11
11
|
#
|
12
|
-
# * +wrapped_methods+ - specifies additional
|
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
|
-
|
49
|
-
|
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:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- mandaryn
|