lib/phony_rails.rb in phony_rails-0.1.8 vs lib/phony_rails.rb in phony_rails-0.1.9
- old
+ new
@@ -64,12 +64,15 @@
# It checks your model object for a a country_code attribute (eg. 'NL') to do the normalizing so make sure
# you've geocoded before calling this method!
def phony_normalize(*attributes)
options = attributes.last.is_a?(Hash) ? attributes.pop : {}
options.assert_valid_keys :country_code, :default_country_code, :as
- raise ArgumentError, ':as option can not be used on phony_normalize with multiple attribute names! (PhonyRails)' if !options[:as].blank? && attributes.size > 1
+ if options[:as].present?
+ raise ArgumentError, ':as option can not be used on phony_normalize with multiple attribute names! (PhonyRails)' if attributes.size > 1
+ raise ArgumentError, "'#{options[:as]}' is not an attribute on #{self.class}. You might want to use 'phony_normalized_method :#{attributes.first}' (PhonyRails)" if not self.attribute_method?(options[:as])
+ end
attributes.each do |attribute|
- raise ArgumentError, "No attribute #{attribute} found on #{self.class.name} (PhonyRails)" if not self.attribute_method?(attribute)
+ raise ArgumentError, "No attribute #{attribute} found on #{self.name} (PhonyRails)" if not self.attribute_method?(attribute)
# Add before validation that saves a normalized version of the phone number
self.before_validation do
set_phony_normalized_numbers(attributes, options)
end
end