59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/has_handle_fallback.rb', line 59
def handle_is_valid
raw = read_attribute self.class.has_handle_fallback_options[:handle_column]
if raw.blank? and (!raw.nil? or has_handle_fallback_options[:required])
errors.add self.class.has_handle_fallback_options[:handle_column], "can't be blank"
end
return if raw.nil?
if raw =~ HasHandleFallback::RECORD_ID_REGEXP
errors.add self.class.has_handle_fallback_options[:handle_column], "can't be entirely composed of integers"
end
if has_handle_fallback_options[:validates_format] and raw !~ HasHandleFallback::REGEXP
errors.add self.class.has_handle_fallback_options[:handle_column], "contains invalid characters"
end
unless HasHandleFallback::LENGTH_RANGE.include? raw.length
errors.add self.class.has_handle_fallback_options[:handle_column], "must be #{HasHandleFallback::LENGTH_RANGE} characters in length"
end
if ValidatesDecencyOf.indecent? raw
errors.add self.class.has_handle_fallback_options[:handle_column], "is indecent"
end
if new_record? and self.class.exists? [ "#{self.class.quoted_table_name}.`#{self.class.has_handle_fallback_options[:handle_column]}` LIKE ?", raw ]
errors.add self.class.has_handle_fallback_options[:handle_column], "isn't unique"
end
if !new_record? and self.class.exists? [ "#{self.class.quoted_table_name}.`#{self.class.primary_key}` <> ? AND #{self.class.quoted_table_name}.`#{self.class.has_handle_fallback_options[:handle_column]}` LIKE ?", id, raw ]
errors.add self.class.has_handle_fallback_options[:handle_column], "isn't unique"
end
end
|