Column behavior based on PostgreSQL adapter in Rails. @see ActiveRecord::ConnectionAdapters::JdbcColumn
# File lib/arjdbc/postgresql/column.rb, line 13 def self.included(base) # NOTE: assumes a standalone PostgreSQLColumn class class << base attr_accessor :money_precision # Loads pg_array_parser if available. String parsing can be # performed quicker by a native extension, which will not create # a large amount of Ruby objects that will need to be garbage # collected. pg_array_parser has a C and Java extension begin require 'pg_array_parser' include PgArrayParser rescue LoadError require 'arjdbc/postgresql/base/array_parser' include ActiveRecord::ConnectionAdapters::PostgreSQL::ArrayParser end if AR4_COMPAT include Cast end end
# File lib/arjdbc/postgresql/column.rb, line 44 def accessor; oid_type.accessor end
# File lib/arjdbc/postgresql/column.rb, line 46 def array?; array; end
Extracts the value from a PostgreSQL column default definition.
@override JdbcColumn#default_value NOTE: based on `self.extract_value_from_default(default)` code
# File lib/arjdbc/postgresql/column.rb, line 55 def default_value(default) # This is a performance optimization for Ruby 1.9.2 in development. # If the value is nil, we return nil straight away without checking # the regular expressions. If we check each regular expression, # Regexp#=== will call NilClass#to_str, which will trigger # method_missing (defined by whiny nil in ActiveSupport) which # makes this method very very slow. return default unless default case default when /\A'(.*)'::(num|date|tstz|ts|int4|int8)range\z/ $1 # Numeric types when /\A\(?(-?\d+(\.\d*)?\)?(::bigint)?)\z/ $1 # Character types when /\A\(?'(.*)'::.*\b(?:character varying|bpchar|text)\z/ $1 # Binary data types when /\A'(.*)'::bytea\z/ $1 # Date/time types when /\A'(.+)'::(?:time(?:stamp)? with(?:out)? time zone|date)\z/ $1 when /\A'(.*)'::interval\z/ $1 # Boolean type when 'true' true when 'false' false # Geometric types when /\A'(.*)'::(?:point|line|lseg|box|"?path"?|polygon|circle)\z/ $1 # Network address types when /\A'(.*)'::(?:cidr|inet|macaddr)\z/ $1 # Bit string types when /\AB'(.*)'::"?bit(?: varying)?"?\z/ $1 # XML type when /\A'(.*)'::xml\z/ $1 # Arrays when /\A'(.*)'::"?\D+"?\[\]\z/ $1 when /\AARRAY\[(.*)\](::\D+)?\z/ "{#{$1.gsub(/'(.*?)'::[a-z]+(,)?\s?/, '\1\2')}}" # Hstore when /\A'(.*)'::hstore\z/ $1 # JSON when /\A'(.*)'::json\z/ $1 # Object identifier types when /\A-?\d+\z/ $1 else # Anything else is blank, some user type, or some function # and we can't know the value of that, so return nil. nil end end
# File lib/arjdbc/postgresql/column.rb, line 48 def number?; !array && super end
@private
# File lib/arjdbc/postgresql/column.rb, line 37 def oid_type @oid_type ||= begin raise "oid not defined" unless oid = (@oid ||= nil) @adapter.get_oid_type(oid.to_i, @fmod.to_i, name) end end
# File lib/arjdbc/postgresql/column.rb, line 49 def text?; !array && super end
Casts value (which is a String) to an appropriate instance. @private
# File lib/arjdbc/postgresql/column.rb, line 121 def type_cast(value) # AR < 4.0 version return if value.nil? return super if respond_to?(:encoded?) && encoded? # since AR-3.2 case sql_type when 'money' self.class.string_to_money(value) else super end end
Generated with the Darkfish Rdoc Generator 2.