Class: Joiner::Joins

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

Constant Summary collapse

ACTIVE_RECORD_VERSION =
Gem::Version.new(ActiveRecord::VERSION::STRING)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Joins

Returns a new instance of Joins.



9
10
11
12
# File 'lib/joiner/joins.rb', line 9

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

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

Instance Method Details

#add_join_to(path) ⇒ Object



14
15
16
17
18
# File 'lib/joiner/joins.rb', line 14

def add_join_to(path)
  return if path.empty?

  joins_cache.add path_as_hash(path)
end

#alias_for(path) ⇒ Object



20
21
22
23
24
25
# File 'lib/joiner/joins.rb', line 20

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

  add_join_to path
  association_for(path).tables.first.name
end

#join_valuesObject



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

def join_values
  Joiner::JoinDependency.new(
    model, table, joins_cache.to_a, Arel::Nodes::OuterJoin
  )
end