Class: OccamsRecord::BindsConverter::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/occams-record/binds_converter/abstract.rb

Overview

A base class for converting a SQL string with Rails-style query params (?, :foo) to native Ruby format (%s, %foo).

It works kind of like a tokenizer. Subclasses must 1) implement get_bind to return the converted bind from the current position and 2) pass the bind sigil (e.g. ?, :) to the parent constructor.

Direct Known Subclasses

Positional

Constant Summary collapse

ESCAPE =
"\\".freeze

Instance Method Summary collapse

Constructor Details

#initialize(sql, bind_sigil) ⇒ Abstract

Returns a new instance of Abstract.



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

def initialize(sql, bind_sigil)
  @sql = sql
  @end = sql.size - 1
  @start_i, @i = 0, 0
  @bind_sigil = bind_sigil
end

Instance Method Details

#to_sString

Returns The converted SQL string.

Returns:

  • (String)

    The converted SQL string



21
22
23
24
25
# File 'lib/occams-record/binds_converter/abstract.rb', line 21

def to_s
  sql = ""
  each { |frag| sql << frag }
  sql
end