Class: ActiveRecordUpsert::Arel::InsertManager::OnDuplicate

Inherits:
Arel::Nodes::Node
  • Object
show all
Defined in:
lib/active_record_upsert/arel/insert_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expr, columns) ⇒ OnDuplicate

Returns a new instance of OnDuplicate.



11
12
13
14
# File 'lib/active_record_upsert/arel/insert_manager.rb', line 11

def initialize(expr, columns)
  @expr = expr
  @columns = columns
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



9
10
11
# File 'lib/active_record_upsert/arel/insert_manager.rb', line 9

def columns
  @columns
end

Instance Method Details

#exprObject

rubocop:disable Metrics/MethodLength



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_record_upsert/arel/insert_manager.rb', line 16

def expr # rubocop:disable Metrics/MethodLength
  case @expr
    when nil
      eq(first_col, first_col)

    when String
      sql(@expr)

    when Hash
      @expr.map do |key, val|
        eq(sql(key.to_s), sql(val))
      end

    else
      @expr
  end
end