Permalink
Browse files

push `extract_scale` to the `Type`.

  - `extract_precision`, `extract_limit`, and `extract_default` probably need to follow.
  - would be good to remove the delegation `Column#extract_scale`.

/cc @sgrif
  • Loading branch information...
1 parent 6b4f6d0 commit 1a92f4fb6574100fb9d16cf3f8e395c3a58938d6 @senny senny committed May 21, 2014
@@ -69,7 +69,7 @@ def extract_default(default)
end
private
- delegate :extract_scale, to: Type
+ delegate :extract_scale, to: :cast_type
def extract_limit(sql_type)
$1.to_i if sql_type =~ /\((.*)\)/
@@ -123,12 +123,6 @@ def extract_limit(sql_type)
end
end
- # Extracts the scale from PostgreSQL-specific data types.
- def extract_scale(sql_type)
- # Money type has a fixed scale of 2.
- sql_type =~ /^money/ ? 2 : super
- end
-
# Extracts the precision from PostgreSQL-specific data types.
def extract_precision(sql_type)
if sql_type == 'money'
@@ -39,6 +39,10 @@ def cast_value(value)
class Money < Type::Decimal
include Infinity
+ def extract_scale(sql_type)
+ 2
+ end
+
def cast_value(value)
return value unless ::String === value
@@ -4,6 +4,10 @@ module Type
class Value # :nodoc:
def type; end
+ def extract_scale(sql_type)
+ Type.extract_scale(sql_type)
+ end
+
def type_cast(value)
cast_value(value) unless value.nil?
end

1 comment on commit 1a92f4f

Member

sgrif commented on 1a92f4f May 21, 2014

👍

Please sign in to comment.