lib/phony_rails.rb in phony_rails-0.2.0 vs lib/phony_rails.rb in phony_rails-0.2.1

- old
+ new

@@ -47,10 +47,11 @@ def set_phony_normalized_numbers(attributes, options = {}) options = options.clone options[:country_code] ||= self.country_code if self.respond_to?(:country_code) attributes.each do |attribute| attribute_name = options[:as] || attribute + raise RuntimeError, "No attribute #{attribute_name} found on #{self.class.name} (PhonyRails)" if not self.attribute_method?(attribute_name) write_attribute(attribute_name, PhonyRails.normalize_number(read_attribute(attribute), options)) end end end @@ -67,15 +68,12 @@ options.assert_valid_keys :country_code, :default_country_code, :as 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.name}. 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.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 + # Add before validation that saves a normalized version of the phone number + self.before_validation do + set_phony_normalized_numbers(attributes, options) end end # Usage: # phony_normalized_method :fax_number, :default_country_code => 'US'