Class: Exwiw::QueryAst::JoinClause

Inherits:
Object
  • Object
show all
Defined in:
lib/exwiw/query_ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_table_name:, foreign_key:, join_table_name:, primary_key:, where_clauses: []) ⇒ JoinClause

Returns a new instance of JoinClause.



8
9
10
11
12
13
14
# File 'lib/exwiw/query_ast.rb', line 8

def initialize(base_table_name:, foreign_key:, join_table_name:, primary_key:, where_clauses: [])
  @base_table_name = base_table_name
  @foreign_key = foreign_key
  @join_table_name = join_table_name
  @primary_key = primary_key
  @where_clauses = where_clauses
end

Instance Attribute Details

#base_table_nameObject (readonly)

Returns the value of attribute base_table_name.



6
7
8
# File 'lib/exwiw/query_ast.rb', line 6

def base_table_name
  @base_table_name
end

#foreign_keyObject (readonly)

Returns the value of attribute foreign_key.



6
7
8
# File 'lib/exwiw/query_ast.rb', line 6

def foreign_key
  @foreign_key
end

#join_table_nameObject (readonly)

Returns the value of attribute join_table_name.



6
7
8
# File 'lib/exwiw/query_ast.rb', line 6

def join_table_name
  @join_table_name
end

#primary_keyObject (readonly)

Returns the value of attribute primary_key.



6
7
8
# File 'lib/exwiw/query_ast.rb', line 6

def primary_key
  @primary_key
end

#where_clausesObject (readonly)

Returns the value of attribute where_clauses.



6
7
8
# File 'lib/exwiw/query_ast.rb', line 6

def where_clauses
  @where_clauses
end

Instance Method Details

#to_hObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/exwiw/query_ast.rb', line 16

def to_h
  hash = {
    base_table_name: base_table_name,
    foreign_key: foreign_key,
    join_table_name: join_table_name,
    primary_key: primary_key,
  }
  if where_clauses.size.positive?
    hash[:where_clauses] = where_clauses.map { |wc| wc.is_a?(String) ? wc : wc.to_h }
  end
  hash
end