Skip to content

Commit

Permalink
extract the string handling part to a method.
Browse files Browse the repository at this point in the history
We know the structure passed in to the `construct` method will be a
hash, so we don't need to test it all the time.  The key value will be a
symbol or string, so handle it with the special method
  • Loading branch information
tenderlove committed Oct 7, 2013
1 parent 77e5c12 commit d2d6e4a
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions activerecord/lib/active_record/associations/join_dependency.rb
Expand Up @@ -182,24 +182,24 @@ def build_join_association(reflection, parent, join_type)
end end


def construct(parent, associations, join_parts, row) def construct(parent, associations, join_parts, row)
case associations associations.sort_by { |k,_| k.to_s }.each do |association_name, assoc|
when Symbol, String association = construct_scalar(parent, association_name, join_parts, row)
name = associations.to_s construct(association, assoc, join_parts, row) if association
end
end


join_part = join_parts.detect { |j| def construct_scalar(parent, associations, join_parts, row)
j.reflection.name.to_s == name && name = associations.to_s
j.parent_table_name == parent.class.table_name }


raise(ConfigurationError, "No such association") unless join_part join_part = join_parts.detect { |j|
j.reflection.name.to_s == name &&
j.parent_table_name == parent.class.table_name
}


join_parts.delete(join_part) raise(ConfigurationError, "No such association") unless join_part
construct_association(parent, join_part, row)
when Hash join_parts.delete(join_part)
associations.sort_by { |k,_| k.to_s }.each do |association_name, assoc| construct_association(parent, join_part, row)
association = construct(parent, association_name, join_parts, row)
construct(association, assoc, join_parts, row) if association
end
end
end end


def construct_association(record, join_part, row) def construct_association(record, join_part, row)
Expand Down

0 comments on commit d2d6e4a

Please sign in to comment.