From 0b6281a4f7697893c049b3438f2db4111099a0be Mon Sep 17 00:00:00 2001 From: Toxix Date: Tue, 18 Mar 2014 01:04:28 +0100 Subject: [PATCH 1/3] Fix: Not set country_code when called with default_country_code Do not set country_code from object if default_country_code is provided. This is needed as you do not want to set a forced country_code if you just define a fallback. --- lib/phony_rails.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/phony_rails.rb b/lib/phony_rails.rb index 4b956f3..f7d3fdb 100644 --- a/lib/phony_rails.rb +++ b/lib/phony_rails.rb @@ -46,7 +46,7 @@ module Extension # 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) + options[:country_code] ||= self.country_code if self.respond_to?(:country_code) && !options[:default_country_code].present? attributes.each do |attribute| attribute_name = options[:as] || attribute raise RuntimeError, "No attribute #{attribute_name} found on #{self.class.name} (PhonyRails)" if not self.class.attribute_method?(attribute_name) @@ -86,7 +86,7 @@ def phony_normalized_method(*attributes) define_method :"normalized_#{attribute}" do |*args| options = args.first || {} raise ArgumentError, "No attribute/method #{attribute} found on #{self.class.name} (PhonyRails)" if not self.respond_to?(attribute) - options[:country_code] ||= self.country_code if self.respond_to?(:country_code) + options[:country_code] ||= self.country_code if self.respond_to?(:country_code) && !options[:default_country_code].present? PhonyRails.normalize_number(self.send(attribute), main_options.merge(options)) end end From bf1ce1594df380a181492ad2c44ca6ea5f9ecb09 Mon Sep 17 00:00:00 2001 From: Toxix Date: Tue, 18 Mar 2014 01:16:32 +0100 Subject: [PATCH 2/3] add german error message --- lib/phony_rails/locales/de.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 lib/phony_rails/locales/de.yml diff --git a/lib/phony_rails/locales/de.yml b/lib/phony_rails/locales/de.yml new file mode 100644 index 0000000..7d20cd7 --- /dev/null +++ b/lib/phony_rails/locales/de.yml @@ -0,0 +1,4 @@ +de: + errors: + messages: + improbable_phone: "ist keine gültige Nummer" From b540b35b207c9a1e04792e61185934d61e0a30e1 Mon Sep 17 00:00:00 2001 From: Toxix Date: Tue, 18 Mar 2014 01:22:26 +0100 Subject: [PATCH 3/3] fix for pull request --- lib/phony_rails.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/phony_rails.rb b/lib/phony_rails.rb index f7d3fdb..4b956f3 100644 --- a/lib/phony_rails.rb +++ b/lib/phony_rails.rb @@ -46,7 +46,7 @@ module Extension # 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) && !options[:default_country_code].present? + 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.class.attribute_method?(attribute_name) @@ -86,7 +86,7 @@ def phony_normalized_method(*attributes) define_method :"normalized_#{attribute}" do |*args| options = args.first || {} raise ArgumentError, "No attribute/method #{attribute} found on #{self.class.name} (PhonyRails)" if not self.respond_to?(attribute) - options[:country_code] ||= self.country_code if self.respond_to?(:country_code) && !options[:default_country_code].present? + options[:country_code] ||= self.country_code if self.respond_to?(:country_code) PhonyRails.normalize_number(self.send(attribute), main_options.merge(options)) end end