lib/phony_rails.rb in phony_rails-0.1.7 vs lib/phony_rails.rb in phony_rails-0.1.8

- old
+ new

@@ -38,13 +38,13 @@ base.send :include, InstanceMethods base.extend ClassMethods end module InstanceMethods - - private + private + # This methods sets the attribute to the normalized version. # It also adds the country_code (number), eg. 31 for NL numbers. def set_phony_normalized_numbers(attributes, options = {}) options = options.clone options[:country_code] ||= self.country_code if self.respond_to?(:country_code) @@ -68,21 +68,21 @@ 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 attributes.each do |attribute| raise ArgumentError, "No attribute #{attribute} found on #{self.class.name} (PhonyRails)" if not self.attribute_method?(attribute) # Add before validation that saves a normalized version of the phone number - self.before_validation do + self.before_validation do set_phony_normalized_numbers(attributes, options) end end end # Usage: # phony_normalized_method :fax_number, :default_country_code => 'US' # Creates a normalized_fax_number method. def phony_normalized_method(*attributes) - main_options = attributes.last.is_a?(Hash) ? attributes.pop : {} + main_options = attributes.last.is_a?(Hash) ? attributes.pop : {} main_options.assert_valid_keys :country_code, :default_country_code attributes.each do |attribute| raise StandardError, "Instance method normalized_#{attribute} already exists on #{self.name} (PhonyRails)" if self.instance_methods.include?(:"normalized_#{attribute}") define_method :"normalized_#{attribute}" do |options = {}| raise ArgumentError, "No attribute/method #{attribute} found on #{self.class.name} (PhonyRails)" if not self.respond_to?(attribute) @@ -95,6 +95,11 @@ end end end -ActiveRecord::Base.extend PhonyRails::ActiveRecordExtension \ No newline at end of file + +ActiveRecord::Base.extend PhonyRails::ActiveRecordExtension + +Dir["#{File.dirname(__FILE__)}/phony_rails/locales/*.yml"].each do |file| + I18n.load_path << file +end