Class: YeSQL::Bindings::Extract

Inherits:
Object
  • Object
show all
Includes:
Common::Adapter
Defined in:
lib/yesql/bindings/extract.rb

Instance Method Summary collapse

Methods included from Common::Adapter

#adapter, #mysql?, #pg?

Constructor Details

#initialize(hash, indexed_bindings, index, value) ⇒ Extract

Returns a new instance of Extract.



11
12
13
14
15
16
# File 'lib/yesql/bindings/extract.rb', line 11

def initialize(hash, indexed_bindings, index, value)
  @hash = hash
  @index = index
  @indexed_bindings = indexed_bindings
  @value = value
end

Instance Method Details

#bind_valsObject



18
19
20
21
22
# File 'lib/yesql/bindings/extract.rb', line 18

def bind_vals
  return [nil, value] unless array?

  value.map { |bind| [nil, bind] }
end

#bind_varsObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yesql/bindings/extract.rb', line 24

def bind_vars
  if mysql?
    return "?" unless array?

    Array.new(size, "?").join(", ")
  elsif pg?
    return "$#{last_val}" unless array?

    value.map.with_index(bind_index) { |_, i| "$#{i}" }.join(", ")
  end
end

#last_valObject



36
37
38
# File 'lib/yesql/bindings/extract.rb', line 36

def last_val
  prev_last_val + current_val_size
end

#prevObject



40
41
42
43
44
# File 'lib/yesql/bindings/extract.rb', line 40

def prev
  return if first?

  indexed_bindings[index - 2].first
end