From bbd8478d795dff4969369cc96aa68d7dfbad868d Mon Sep 17 00:00:00 2001 From: Cairo Noleto Date: Wed, 13 Jun 2012 09:16:10 -0300 Subject: [PATCH] Minor refactoring --- lib/i18n_alchemy/proxy.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/i18n_alchemy/proxy.rb b/lib/i18n_alchemy/proxy.rb index bfdbad1..64abc1a 100644 --- a/lib/i18n_alchemy/proxy.rb +++ b/lib/i18n_alchemy/proxy.rb @@ -53,12 +53,11 @@ def method_missing(*args, &block) private def active_record_compatible? - target_class = @target.class target_class.respond_to?(:columns) && target_class.respond_to?(:nested_attributes_options) end def build_attributes - @target.class.columns.each do |column| + columns.each do |column| column_name = column.name next if column.primary || column_name.ends_with?("_id") || @localized_attributes.key?(column_name) @@ -68,7 +67,7 @@ def build_attributes end def build_methods - @target.class.localized_methods.each_pair do |method, parser_type| + localized_methods.each_pair do |method, parser_type| method = method.to_s parser = detect_parser(parser_type) build_attribute(method, parser) @@ -133,6 +132,18 @@ def detect_parser(type_or_parser) type_or_parser end end + + def localized_methods + target_class.localized_methods + end + + def columns + target_class.columns + end + + def target_class + @target.class + end end end end