Skip to content

Commit

Permalink
Cache de target class to avoid calling the method everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Aug 31, 2013
1 parent 47ea026 commit d202132
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/i18n_alchemy/proxy.rb
Expand Up @@ -11,6 +11,7 @@ class Proxy < base_proxy
# Find a better way to find that and skip these columns.
def initialize(target, attributes = nil)
@target = target
@target_class = target.class

@localized_attributes = {}
@localized_associations = []
Expand Down Expand Up @@ -62,12 +63,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)
@target_class.respond_to?(:columns) && @target_class.respond_to?(:nested_attributes_options)
end

def build_attributes
@target.class.columns.each do |column|
@target_class.columns.each do |column|
column_name = column.name
next if column.primary || column_name.ends_with?("_id") || @localized_attributes.key?(column_name)

Expand All @@ -77,15 +77,15 @@ def build_attributes
end

def build_methods
@target.class.localized_methods.each_pair do |method, parser_type|
@target_class.localized_methods.each_pair do |method, parser_type|
method = method.to_s
parser = detect_parser(parser_type)
build_attribute(method, parser)
end
end

def build_associations
@target.class.nested_attributes_options.each_key do |association_name|
@target_class.nested_attributes_options.each_key do |association_name|
create_localized_association(association_name)
end
end
Expand All @@ -98,7 +98,7 @@ def build_attribute(name, parser)

def create_localized_association(association_name)
@localized_associations <<
AssociationParser.new(@target.class, association_name)
AssociationParser.new(@target_class, association_name)
end

def create_localized_attribute(column_name, parser)
Expand Down

0 comments on commit d202132

Please sign in to comment.