Module: OccamsRecord::BindsConverter

Defined in:
lib/occams-record/binds_converter.rb,
lib/occams-record/binds_converter/named.rb,
lib/occams-record/binds_converter/abstract.rb,
lib/occams-record/binds_converter/positional.rb

Overview

Classes and methods for converting from Rails-style binds (?, :foo) to native Ruby format (%s, %foo).

Defined Under Namespace

Classes: Abstract, Named, Positional

Class Method Summary collapse

Class Method Details

.convert(sql, binds) ⇒ String

Convert any Rails-style binds (?, :foo) to native Ruby format (%s, %foo).

Parameters:

  • sql (String)
  • binds (Hash|Array)

Returns:

  • (String)

    the converted SQL string



13
14
15
16
17
18
19
20
21
# File 'lib/occams-record/binds_converter.rb', line 13

def self.convert(sql, binds)
  converter =
    case binds
    when Hash then Named.new(sql)
    when Array then Positional.new(sql)
    else raise ArgumentError, "OccamsRecord: Unsupported SQL bind params '#{binds.inspect}'. Only Hash and Array are supported"
    end
  converter.to_s
end