class YeSQL::Bindings::Transformed

Attributes

statement_binds[R]

Public Class Methods

new(statement_binds:) click to toggle source
# File lib/yesql/bindings/transformed.rb, line 11
def initialize(statement_binds:)
  @statement_binds = statement_binds
end

Public Instance Methods

call() click to toggle source
# File lib/yesql/bindings/transformed.rb, line 15
def call
  return mysql_rails5_binds if rails5? && mysql?
  return mysql_binds if !rails5? && mysql?

  pg_binds
end

Private Instance Methods

mysql_binds() click to toggle source
# File lib/yesql/bindings/transformed.rb, line 41
def mysql_binds
  statement_binds
    .map(&:first)
    .flatten
    .each_slice(2)
    .to_a
end
mysql_rails5_binds() click to toggle source
# File lib/yesql/bindings/transformed.rb, line 30
def mysql_rails5_binds
  statement_binds
    .flat_map(&:first)
    .each_slice(2)
    .flat_map do |first, last|
      next [first, last].compact.map(&:last) if first.is_a?(Array)

      last
    end
end
pg_binds() click to toggle source
# File lib/yesql/bindings/transformed.rb, line 49
def pg_binds
  statement_binds
    .sort_by { |_, position| position.to_s.tr("$", "").to_i }
    .uniq
    .map(&:first)
    .flatten
    .each_slice(2)
    .to_a
end
rails5?() click to toggle source
# File lib/yesql/bindings/transformed.rb, line 26
def rails5?
  ::ActiveRecord::VERSION::MAJOR == 5
end