Class: Ferret::Parameter_Collector

Inherits:
Array
  • Object
show all
Defined in:
lib/sql-ferret.rb

Instance Method Summary collapse

Instance Method Details

#feed(parameter, exemplar_spec) ⇒ Object

[parameter]

can be a plain value, a collection

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



1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
# 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_hashObject



1712
1713
1714
1715
1716
1717
1718
# 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