has_handle_fallback 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/VERSION +1 -1
- data/lib/has_handle_fallback.rb +4 -4
- metadata +1 -1
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/has_handle_fallback.rb
CHANGED
@@ -6,8 +6,8 @@ module HasHandleFallback
|
|
6
6
|
RECORD_ID_REGEXP = /\A\d+\z/
|
7
7
|
|
8
8
|
def self.str2handle(str)
|
9
|
-
str = str.gsub ANTI_REGEXP, ''
|
10
|
-
str << ('_' * LENGTH_RANGE.min - str.length) unless LENGTH_RANGE.include?(str.length)
|
9
|
+
str = str.to_s.gsub ANTI_REGEXP, ''
|
10
|
+
str << ('_' * (LENGTH_RANGE.min - str.length)) unless LENGTH_RANGE.include?(str.length)
|
11
11
|
str
|
12
12
|
end
|
13
13
|
|
@@ -74,7 +74,7 @@ module HasHandleFallback
|
|
74
74
|
end
|
75
75
|
|
76
76
|
# validates_uniqueness_of :handle, :case_sensitive => false, :allow_nil => true
|
77
|
-
if self.class.exists? [ "LOWER(#{self.class.quoted_table_name}.`#{self.class.has_handle_fallback_options[:handle_column]}`) = ?", raw.downcase ]
|
77
|
+
if self.class.exists? [ "#{self.class.quoted_table_name}.`#{self.class.primary_key}` <> ? AND LOWER(#{self.class.quoted_table_name}.`#{self.class.has_handle_fallback_options[:handle_column]}`) = ?", id, raw.downcase ]
|
78
78
|
errors.add self.class.has_handle_fallback_options[:handle_column], "isn't unique"
|
79
79
|
end
|
80
80
|
end
|
@@ -86,7 +86,7 @@ module HasHandleFallback
|
|
86
86
|
|
87
87
|
def handle_fallback
|
88
88
|
fallback = read_attribute self.class.has_handle_fallback_options[:fallback_column]
|
89
|
-
fallback = fallback.split('@').first if fallback.include? '@'
|
89
|
+
fallback = fallback.split('@').first if fallback.to_s.include? '@'
|
90
90
|
HasHandleFallback.str2handle fallback
|
91
91
|
end
|
92
92
|
|