148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/td/client/api.rb', line 148
def self.validate_name(target, min_len, max_len, name)
if !target.instance_of?(String) || target.empty?
raise ParameterValidationError,
"A valid target name is required"
end
name = name.to_s
if max_len
if name.length < min_len || name.length > max_len
raise ParameterValidationError,
"#{target.capitalize} name must be between #{min_len} and #{max_len} characters long. Got #{name.length} " +
(name.length == 1 ? "character" : "characters") + "."
end
else
if min_len == 1
if name.empty?
raise ParameterValidationError,
"Empty #{target} name is not allowed"
end
else
if name.length < min_len
raise ParameterValidationError,
"#{target.capitalize} name must be longer than #{min_len} characters. Got #{name.length} " +
(name.length == 1 ? "character" : "characters") + "."
end
end
end
unless name =~ /^([a-z0-9_]+)$/
raise ParameterValidationError,
"#{target.capitalize} name must only consist of lower-case alpha-numeric characters and '_'."
end
name
end
|