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

Returns a new instance of 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
  association_for(path).tables.first.name
end

#join_valuesObject



25
26
27
28
29
30
31
32
33
# File 'lib/joiner/joins.rb', line 25

def join_values
  if Joiner::JoinDependency.instance_method(:initialize).arity == 3
    # ActiveRecord 5.2.1+
    Joiner::JoinDependency.new model, table, joins_cache.to_a
  else
    # ActiveRecord 5.2.0
    Joiner::JoinDependency.new model, table, joins_cache.to_a, alias_tracker
  end
end