Skip to content

Commit

Permalink
fix the variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Oct 3, 2013
1 parent cb0aa02 commit 7768c2a
Showing 1 changed file with 7 additions and 7 deletions.
Expand Up @@ -4,28 +4,28 @@ class JoinTableResolver
KnownTable = Struct.new :join_table KnownTable = Struct.new :join_table


class KnownClass class KnownClass
def initialize(rhs_class, lhs_class_name) def initialize(lhs_class, rhs_class_name)
@rhs_class = rhs_class @lhs_class = lhs_class
@lhs_class_name = lhs_class_name @rhs_class_name = rhs_class_name
@join_table = nil @join_table = nil
end end


def join_table def join_table
@join_table ||= [@rhs_class.table_name, klass.table_name].sort.join("\0").gsub(/^(.*_)(.+)\0\1(.+)/, '\1\2_\3').gsub("\0", "_") @join_table ||= [@lhs_class.table_name, klass.table_name].sort.join("\0").gsub(/^(.*_)(.+)\0\1(.+)/, '\1\2_\3').gsub("\0", "_")
end end


private private
def klass; @lhs_class_name.constantize; end def klass; @rhs_class_name.constantize; end
end end


def self.build(rhs_class, name, options) def self.build(lhs_class, name, options)
if options[:join_table] if options[:join_table]
KnownTable.new options[:join_table] KnownTable.new options[:join_table]
else else
class_name = options.fetch(:class_name) { class_name = options.fetch(:class_name) {
name.to_s.camelize.singularize name.to_s.camelize.singularize
} }
KnownClass.new rhs_class, class_name KnownClass.new lhs_class, class_name
end end
end end
end end
Expand Down

0 comments on commit 7768c2a

Please sign in to comment.