lib/phony_rails.rb in phony_rails-0.1.12 vs lib/phony_rails.rb in phony_rails-0.2.0
- old
+ new
@@ -1,7 +1,7 @@
require 'phony'
-require 'countries'
+require 'iso3166'
require 'phony_rails/string_extensions'
require 'validators/phony_validator'
require 'phony_rails/version'
module PhonyRails
@@ -23,18 +23,17 @@
return if number.blank?
if country_number = country_number_for(options[:country_code] || options[:default_country_code])
# Add country_number if missing
number = "#{country_number}#{number}" if not number =~ /^(00|\+)?#{country_number}/
end
- number = Phony.normalize(number)
+ number = Phony.normalize(number) if Phony.plausible?(number)
return number.to_s
rescue
number # If all goes wrong .. we still return the original input.
end
- # This module is added to AR.
- module ActiveRecordExtension
+ module Extension
def self.extended(base)
base.send :include, InstanceMethods
base.extend ClassMethods
end
@@ -100,10 +99,16 @@
end
end
-ActiveRecord::Base.extend PhonyRails::ActiveRecordExtension
+# check whether it is ActiveRecord or Mongoid being used
+ActiveRecord::Base.send :extend, PhonyRails::Extension if defined?(ActiveRecord)
+Mongoid::Document.module_eval do
+ def self.included(base)
+ base.extend PhonyRails::Extension
+ end
+end if defined?(Mongoid)
Dir["#{File.dirname(__FILE__)}/phony_rails/locales/*.yml"].each do |file|
I18n.load_path << file
end