Class: OccamsRecord::BindsConverter::Abstract
- Inherits:
-
Object
- Object
- OccamsRecord::BindsConverter::Abstract
- 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
Constant Summary collapse
- ESCAPE =
"\\".freeze
Instance Method Summary collapse
-
#initialize(sql, bind_sigil) ⇒ Abstract
constructor
A new instance of Abstract.
-
#to_s ⇒ String
The converted SQL string.
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_s ⇒ String
Returns 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 |