lib/ahnnotate/column.rb in ahnnotate-0.4.0 vs lib/ahnnotate/column.rb in ahnnotate-0.5.0

- old
+ new

@@ -1,15 +1,34 @@ module Ahnnotate class Column attr_reader :name - attr_reader :type - def initialize(name:, type:, nullable:, primary_key:, default:) + def self.sql_type_map + @sql_type_map ||= + begin + map = Hash.new { |_self, k| k } + map["character varying"] = "varchar" + map["character"] = "char" + map["datetime"] = "timestamp" + map["double precision"] = "double" + map["time with time zone"] = "time" + map["time without time zone"] = "timetz" + map["timestamp with time zone"] = "timestamptz" + map["timestamp without time zone"] = "timestamp" + map + end + end + + def initialize(name:, sql_type:, nullable:, primary_key:, default:) @name = name - @type = type + @sql_type = sql_type.to_s.downcase.gsub(/\(.*?\)/, "") @nullable = nullable @primary_key = primary_key @default = default + end + + def type + self.class.sql_type_map[@sql_type] end def details if @details return @details