Last active
December 15, 2015 23:59
-
-
Save fxn/5344725 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ActiveRecord::ConnectionAdapters::PostgreSQLColumn.class_eval do | |
| prepend Module.new { | |
| def mpq? | |
| type == :mpq | |
| end | |
| def simplified_type(field_type) | |
| field_type == 'mpq' ? :mpq : super | |
| end | |
| def klass | |
| mpq? ? Rational : super | |
| end | |
| def type_cast(string) | |
| if mpq? | |
| string.nil? ? nil : string.to_r | |
| else | |
| super | |
| end | |
| end | |
| def type_cast_code(var_name) | |
| mpq? ? "#{var_name}.to_r" : super | |
| end | |
| } | |
| class << self | |
| prepend Module.new { | |
| def extract_value_from_default(default) | |
| default =~ /\A'(.*)'::mpq\z/ ? $1 : super | |
| end | |
| } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment