Class: Lore::Type_Filters

Inherits:
Object show all
Defined in:
lib/lore/adapters/postgres/types.rb,
lib/lore/adapters/postgres-pr/types.rb

Constant Summary collapse

@@input_filters =
{ 
  PG_VCHAR_LIST          => lambda { |v| "{#{v.join(',')}}" }, 
  PG_BOOL                => lambda { |v| if (v && v != 'f' || v == 't') then 'f' elsif (v.instance_of?(FalseClass) || v == 'f') then 'f' else nil end }, 
  PG_DATE                => lambda { |v| v.to_s }, 
  PG_TIME                => lambda { |v| v.to_s }, 
  PG_TIMESTAMP_TIMEZONE  => lambda { |v| v.to_s }, 
  PG_TIMESTAMP           => lambda { |v| v.to_s }, 
}
@@output_filters =
{ 
  PG_VCHAR_LIST          => lambda { |v| v[1..-2].split(',') }, 
  PG_INT                 => lambda { |v| if v then v.to_i else nil end }, 
  PG_SMALLINT            => lambda { |v| if v then v.to_i else nil end },
  PG_FLOAT               => lambda { |v| if v && v.length > 0 then v.to_f else nil end }, 
  PG_DECIMAL             => lambda { |v| if v && v.length > 0 then v.to_f else nil end }, 
  PG_BOOL                => lambda { |v| if v == 't' then true elsif v == 'f' then false else nil end }
# SLOW!
#     PG_DATE                => lambda { |v| Date.parse(v) if v }, 
#     PG_TIME                => lambda { |v| Time.parse(v) if v }, 
#     PG_TIMESTAMP_TIMEZONE  => lambda { |v| DateTime.parse(v) if v }, 
#     PG_TIMESTAMP           => lambda { |v| DateTime.parse(v) if v }
}

Class Method Summary collapse

Class Method Details

.inObject



81
82
83
# File 'lib/lore/adapters/postgres/types.rb', line 81

def self.in
  @@input_filters
end

.outObject



85
86
87
# File 'lib/lore/adapters/postgres/types.rb', line 85

def self.out
  @@output_filters
end