acts_as_ordinalized 0.1.2 → 0.1.3
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 +13 -8
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/acts_as_ordinalized.gemspec
CHANGED
data/lib/acts_as_ordinalized.rb
CHANGED
@@ -7,18 +7,23 @@ module ActsAsOrdinalized
|
|
7
7
|
# each collection gets new ordinal numbers starting from one
|
8
8
|
# paginated results should also get correct ordinal numbers on subsequent pages
|
9
9
|
module ClassMethods
|
10
|
-
|
10
|
+
# Configuration options are:
|
11
|
+
#
|
12
|
+
# * +wrapped_methods+ - specifies additional classmethods that should be wrapped with functionality (basic are find and paginate)
|
13
|
+
def acts_as_ordinalized(options = {})
|
11
14
|
attr_accessor :ordinal_number
|
15
|
+
wrapped_methods = ([:paginate, :find] << options[:wrapped_methods]).flatten.compact
|
12
16
|
|
13
|
-
#wrap find with
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
#wrap various find methods with adding ordinal numbers to all returned models
|
18
|
+
wrapped_methods.each do |method_name|
|
19
|
+
if self.respond_to?(method_name)
|
20
|
+
class_eval <<-EOV
|
21
|
+
def self.#{method_name}(*args)
|
22
|
+
ActsAsOrdinalized.ordinalize(super(*args))
|
23
|
+
end
|
24
|
+
EOV
|
17
25
|
end
|
18
26
|
end
|
19
|
-
def self.find(*args)
|
20
|
-
ActsAsOrdinalized.ordinalize(super(*args))
|
21
|
-
end
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
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: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- mandaryn
|