Class/Module Index [+]

Quicksearch

JdbcSpec::PostgreSQL::Column

Public Instance Methods

cast_to_boolean(value) click to toggle source
# File lib/jdbc_adapter/jdbc_postgre.rb, line 52
def cast_to_boolean(value)
  return nil if value.nil?
  if value == true || value == false
    value
  else
    %(true t 1).include?(value.to_s.downcase)
  end
end
default_value(value) click to toggle source

Post process default value from JDBC into a Rails-friendly format (columns{-internal})

# File lib/jdbc_adapter/jdbc_postgre.rb, line 62
def default_value(value)
  # Boolean types
  return "t" if value =~ /true/
  return "f" if value =~ /false/

  # Char/String/Bytea type values
  return $1 if value =~ /^'(.*)'::(bpchar|text|character varying|bytea)$/

  # Numeric values
  return value if value =~ /^-?[0-9]+(\.[0-9]*)?/

  # Fixed dates / timestamp
  return $1 if value =~ /^'(.+)'::(date|timestamp)/

  # Anything else is blank, some user type, or some function
  # and we can't know the value of that, so return nil.
  return nil
end
simplified_type(field_type) click to toggle source
# File lib/jdbc_adapter/jdbc_postgre.rb, line 41
def simplified_type(field_type)
  return :integer if field_type =~ /^serial/
  return :string if field_type =~ /\[\]$/ || field_type =~ /^interval/
  return :string if field_type =~ /^(?:point|lseg|box|"?path"?|polygon|circle)/
  return :datetime if field_type =~ /^timestamp/
  return :float if field_type =~ /^real|^money/
  return :binary if field_type =~ /^bytea/
  return :boolean if field_type =~ /^bool/
  super
end
type_cast(value) click to toggle source
# File lib/jdbc_adapter/jdbc_postgre.rb, line 34
def type_cast(value)
  case type
  when :boolean then cast_to_boolean(value)
  else super
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.