aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/decimal.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/type/decimal.rb')
-rw-r--r--activerecord/lib/active_record/type/decimal.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/type/decimal.rb b/activerecord/lib/active_record/type/decimal.rb
new file mode 100644
index 0000000000..1c0147a797
--- /dev/null
+++ b/activerecord/lib/active_record/type/decimal.rb
@@ -0,0 +1,25 @@
+module ActiveRecord
+ module Type
+ class Decimal < Value # :nodoc:
+ include Numeric
+
+ def type
+ :decimal
+ end
+
+ def klass
+ ::BigDecimal
+ end
+
+ private
+
+ def cast_value(value)
+ if value.respond_to?(:to_d)
+ value.to_d
+ else
+ value.to_s.to_d
+ end
+ end
+ end
+ end
+end