Skip to content

Commit

Permalink
push extract_scale to the Type.
Browse files Browse the repository at this point in the history
  - `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
senny committed May 21, 2014
1 parent 6b4f6d0 commit 1a92f4f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def extract_default(default)
end end


private private
delegate :extract_scale, to: Type delegate :extract_scale, to: :cast_type


def extract_limit(sql_type) def extract_limit(sql_type)
$1.to_i if sql_type =~ /\((.*)\)/ $1.to_i if sql_type =~ /\((.*)\)/
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ def extract_limit(sql_type)
end end
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. # Extracts the precision from PostgreSQL-specific data types.
def extract_precision(sql_type) def extract_precision(sql_type)
if sql_type == 'money' if sql_type == 'money'
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def cast_value(value)
class Money < Type::Decimal class Money < Type::Decimal
include Infinity include Infinity


def extract_scale(sql_type)
2
end

def cast_value(value) def cast_value(value)
return value unless ::String === value return value unless ::String === value


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module Type
class Value # :nodoc: class Value # :nodoc:
def type; end def type; end


def extract_scale(sql_type)
Type.extract_scale(sql_type)
end

def type_cast(value) def type_cast(value)
cast_value(value) unless value.nil? cast_value(value) unless value.nil?
end end
Expand Down

1 comment on commit 1a92f4f

@sgrif
Copy link
Contributor

@sgrif sgrif commented on 1a92f4f May 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.