class Joiner::Joins

Attributes

joins_cache[R]
model[R]

Public Class Methods

new(model) click to toggle source
# File lib/joiner/joins.rb, line 7
def initialize(model)
  @model       = model
  @joins_cache = Set.new
end

Public Instance Methods

add_join_to(path) click to toggle source
# File lib/joiner/joins.rb, line 12
def add_join_to(path)
  return if path.empty?

  joins_cache.add path_as_hash(path)
end
alias_for(path) click to toggle source
# File lib/joiner/joins.rb, line 18
def alias_for(path)
  return model.table_name if path.empty?

  add_join_to path
  association_for(path).table.name
end
join_values() click to toggle source
# File lib/joiner/joins.rb, line 25
def join_values
  Joiner::JoinDependency.new(
    model, table, joins_cache.to_a, Arel::Nodes::OuterJoin
  )
end

Private Instance Methods

alias_tracker() click to toggle source
# File lib/joiner/joins.rb, line 35
def alias_tracker
  Joiner::AliasTracker.create(
    model.connection, table.name, []
  )
end
association_for(path) click to toggle source
# File lib/joiner/joins.rb, line 41
def association_for(path)
  join_values.join_association_for path, alias_tracker
end
path_as_hash(path) click to toggle source
# File lib/joiner/joins.rb, line 45
def path_as_hash(path)
  path[0..-2].reverse.inject(path.last) { |key, item| {item => key} }
end
table() click to toggle source
# File lib/joiner/joins.rb, line 49
def table
  @table ||= model.arel_table
end