Class: Joiner::Joins

Inherits:
Object
  • Object
show all
Defined in:
lib/joiner/joins.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Joins



7
8
9
10
# File 'lib/joiner/joins.rb', line 7

def initialize(model)
  @model       = model
  @joins_cache = Set.new
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/joiner/joins.rb', line 5

def model
  @model
end

Instance Method Details

#add_join_to(path) ⇒ Object



12
13
14
15
16
# 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) ⇒ Object



18
19
20
21
22
23
# File 'lib/joiner/joins.rb', line 18

def alias_for(path)
  return model.table_name if path.empty?

  add_join_to path
  join_values.join_association_for(path, alias_tracker).tables.first.name
end

#join_valuesObject



25
26
27
# File 'lib/joiner/joins.rb', line 25

def join_values
  Joiner::JoinDependency.new model, table, joins_cache.to_a
end