lib/lite/validators/url_validator.rb in lite-validators-1.0.4 vs lib/lite/validators/url_validator.rb in lite-validators-1.0.5
- old
+ new
@@ -8,11 +8,11 @@
http https
].freeze
def validate_each(record, attribute, value)
assign_attr_readers(record, attribute, URI.parse(value.to_s))
- valid?
+ valid_attr?
rescue URI::InvalidURIError
record.errors.add(attribute, *error_message)
end
private
@@ -24,9 +24,11 @@
def error_message_for(option)
options[:message] || I18n.t("errors.messages.url.#{option}")
end
def valid_attr?
+ raise URI::InvalidURIError if value.to_s.strip.empty?
+
valid_uri? && valid_domain? && valid_scheme? && valid_root?
end
# rubocop:disable Metrics/AbcSize
def valid_domain?