class Ferret::Parameter_Collector

Public Instance Methods

feed(parameter, exemplar_spec) click to toggle source
[parameter]

can be a plain value, a collection

([[Enumerator]]) of values, or a [[nil]].

# File lib/sql-ferret.rb, line 1675
def feed parameter, exemplar_spec
  raise 'type mismatch' \
      unless exemplar_spec.is_a? Ferret::Exemplar
  if parameter.nil? and exemplar_spec.column.optional? then
    test = "is " + _feed(nil)
    selects_one_p = false
  else
    *exemplar_values = *parameter # force to array
    exemplar_values.map! do |value|
      Ferret.deterpret exemplar_spec.interpretation, value
    end
    if exemplar_values.length != 1 then
      test = "in ("
      exemplar_values.each_with_index do |value, i|
        test << ", " unless i.zero?
        test << _feed(value)
      end
      test << ")"
      selects_one_p = false
    else
      test = "= " + _feed(exemplar_values.first)
      selects_one_p = exemplar_spec.column.unique?
    end
  end
  return test, selects_one_p
end
to_hash() click to toggle source
# File lib/sql-ferret.rb, line 1712
def to_hash
  h = {}
  each_with_index do |parameter, i|
    h[i.to_s.to_sym] = parameter
  end
  return h
end

Private Instance Methods

_feed(parameter) click to toggle source

Add the given [[parameter]] to this collector and return a string containing its placeholder, in the form of colon followed by a sequential number (0-based).

# File lib/sql-ferret.rb, line 1705
def _feed parameter
  placeholder = length
  push parameter
  return ":#{placeholder}"
end