lib/valvat/active_model.rb in valvat-0.1.1 vs lib/valvat/active_model.rb in valvat-0.2.0
- old
+ new
@@ -5,16 +5,14 @@
module ActiveModel
module Validations
class ValvatValidator < ::ActiveModel::EachValidator
def validate_each(record, attribute, value)
- is_valid = Valvat::Syntax.validate(value)
+ vat = Valvat(value)
- if is_valid && options[:lookup]
- is_valid = Valvat::Lookup.validate(value)
- is_valid.nil? && is_valid = (options[:lookup] != :fail_if_down)
- end
+ is_valid = options[:lookup] ? vat.valid? && vat.exists? : vat.valid?
+ is_valid.nil? && is_valid = (options[:lookup] != :fail_if_down)
unless is_valid
record.errors.add(attribute, :invalid_vat,
:message => options[:message],
:country_adjective => I18n.t(
@@ -26,6 +24,8 @@
end
end
end
end
-I18n.load_path << File.dirname(__FILE__) + '/../locale/en.yml'
+%w(en de).each do |locale|
+ I18n.load_path << "#{File.dirname(__FILE__)}/../locale/#{locale}.yml"
+end
\ No newline at end of file