sortifiable 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ *0.2.3 (May 3rd, 2011)
2
+
3
+ * Rails 3.1 has added Model.foreign_{key,type} to association reflections
4
+
5
+
1
6
  *0.2.2 (May 3rd, 2011)
2
7
 
3
8
  * Ensure that callbacks return true when no updates take place
@@ -1,3 +1,3 @@
1
1
  module Sortifiable
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/sortifiable.rb CHANGED
@@ -53,14 +53,7 @@ module Sortifiable
53
53
  reflection = reflections[options.delete(:scope)]
54
54
 
55
55
  if reflection.belongs_to?
56
- if reflection.options[:polymorphic]
57
- options[:scope] = [
58
- reflection.association_foreign_key.to_sym,
59
- reflection.options[:foreign_type].to_sym
60
- ]
61
- else
62
- options[:scope] = reflection.association_foreign_key.to_sym
63
- end
56
+ options[:scope] = scope_from_association_reflection(reflection)
64
57
  else
65
58
  raise ArgumentError, "Only belongs_to associations can be used as a scope"
66
59
  end
@@ -80,6 +73,24 @@ module Sortifiable
80
73
 
81
74
  self.acts_as_list_options = options
82
75
  end
76
+
77
+ private
78
+ def scope_from_association_reflection(reflection) #:nodoc:
79
+ if reflection.options[:polymorphic]
80
+ if reflection.respond_to?(:foreign_type)
81
+ [reflection.foreign_key, reflection.foreign_type].map(&:to_sym)
82
+ else
83
+ [reflection.association_foreign_key, reflection.options[:foreign_type]].map(&:to_sym)
84
+ end
85
+ else
86
+ if reflection.respond_to?(:foreign_type)
87
+ reflection.foreign_key.to_sym
88
+ else
89
+ reflection.association_foreign_key.to_sym
90
+ end
91
+ end
92
+ end
93
+
83
94
  end
84
95
 
85
96
  # All the methods available to a record that has had <tt>acts_as_list</tt>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortifiable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew White