lib/phony_rails.rb in phony_rails-0.3.2 vs lib/phony_rails.rb in phony_rails-0.4.0
- old
+ new
@@ -35,18 +35,13 @@
rescue
number # If all goes wrong .. we still return the original input.
end
module Extension
+ extend ActiveSupport::Concern
- def self.extended(base)
- base.send :include, InstanceMethods
- base.extend ClassMethods
- end
-
- module InstanceMethods
-
+ included do
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 = {})
@@ -56,11 +51,10 @@
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)
write_attribute(attribute_name, PhonyRails.normalize_number(read_attribute(attribute), options))
end
end
-
end
module ClassMethods
# Use this method on the class level like:
@@ -95,23 +89,22 @@
options[:country_code] ||= self.country_code if self.respond_to?(:country_code)
PhonyRails.normalize_number(self.send(attribute), main_options.merge(options))
end
end
end
-
end
-
end
-
end
# 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
+ActiveRecord::Base.send :include, PhonyRails::Extension if defined?(ActiveRecord)
+
+if defined?(Mongoid)
+ module Mongoid::Phony
+ extend ActiveSupport::Concern
+ include PhonyRails::Extension
end
-end if defined?(Mongoid)
+end
Dir["#{File.dirname(__FILE__)}/phony_rails/locales/*.yml"].each do |file|
I18n.load_path << file
end