Permalink
Browse files

Remove custom parsers in favor of localize override

Allow localize to override automatic attribute definition from column.
This enables us to use custom parsers for columns instead of the
custom_parsers configuration.
  • Loading branch information...
1 parent f8d88d1 commit 3d903d7145b587222504e969eea18e681683d195 @carlosantoniodasilva carlosantoniodasilva committed May 31, 2012
Showing with 7 additions and 14 deletions.
  1. +0 −8 lib/i18n_alchemy.rb
  2. +4 −3 lib/i18n_alchemy/proxy.rb
  3. +1 −1 test/i18n_alchemy/proxy/methods_test.rb
  4. +2 −2 test/models/product.rb
View
@@ -21,10 +21,6 @@ def localized(attributes=nil, *args)
class_attribute :localized_methods,
:instance_reader => false, :instance_writer => false
self.localized_methods = {}
-
- class_attribute :customized_parsers,
- :instance_reader => false, :instance_writer => false
- self.customized_parsers = {}
end
module ClassMethods
@@ -35,10 +31,6 @@ def localize(*methods, options)
end
self.localized_methods = methods
end
-
- def custom_parsers(parsers_hash)
- self.customized_parsers = self.customized_parsers.merge(parsers_hash)
- end
end
end
end
@@ -59,10 +59,11 @@ def active_record_compatible?
def build_attributes
@target.class.columns.each do |column|
- next if column.primary || column.name.ends_with?("_id")
+ column_name = column.name
+ next if column.primary || column_name.ends_with?("_id") || @localized_attributes.key?(column_name)
- parser = @target.class.customized_parsers[column.name.to_sym] || detect_parser_from_column(column)
- build_attribute(column.name, parser)
+ parser = detect_parser_from_column(column)
+ build_attribute(column_name, parser)
end
end
@@ -11,7 +11,7 @@ def test_localizes_numeric_methods
def test_localizes_date_methods
@product.released_at = Date.new(2011, 2, 28)
- assert_equal "03/2011", @localized.estimated_delivery_at
+ assert_equal "05/03/2011", @localized.estimated_delivery_at
end
def test_localizes_time_methods
View
@@ -1,9 +1,9 @@
class Product < ActiveRecord::Base
include I18n::Alchemy
localize :total, :using => :number
- localize :estimated_delivery_at, :using => MyCustomDateParser
+ localize :estimated_delivery_at, :using => :date
localize :estimated_last_comission_payment_at, :using => :timestamp
- custom_parsers :released_month => MyCustomDateParser
+ localize :released_month, :using => MyCustomDateParser
attr_protected :my_precious

0 comments on commit 3d903d7

Please sign in to comment.