diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-17 11:37:43 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-17 11:37:43 -0800 |
commit | 504ed9095810c40b0967802dfbdd347c7e3a4e89 (patch) | |
tree | 25f8549cd5e8af165cc6bd821d8906d1506f022c /activerecord/lib/active_record | |
parent | cc74088c6cd4da7d3ce7bc0d66c4cae509693622 (diff) | |
parent | 49182b87b258786ae5942eeb475618794291e976 (diff) | |
download | rails-504ed9095810c40b0967802dfbdd347c7e3a4e89.tar.gz rails-504ed9095810c40b0967802dfbdd347c7e3a4e89.tar.bz2 rails-504ed9095810c40b0967802dfbdd347c7e3a4e89.zip |
Merge pull request #8542 from le0pard/fixed_ar_intrange
AR supporting new int4range and int8range data type on PostgreSQL >= 9.2. Fix #8528 pull request
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/cast.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb index 3772f7ddaa..f7d734a2f1 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb @@ -97,8 +97,7 @@ module ActiveRecord nil elsif "empty" == string (nil..nil) - elsif String === string - matches = /^(\(|\[)([0-9]+),(\s?)([0-9]+)(\)|\])$/i.match(string) + elsif String === string && (matches = /^(\(|\[)([0-9]+),(\s?)([0-9]+)(\)|\])$/i.match(string)) lower_bound = ("(" == matches[1] ? (matches[2].to_i + 1) : matches[2].to_i) upper_bound = (")" == matches[5] ? (matches[4].to_i - 1) : matches[4].to_i) (lower_bound..upper_bound) @@ -108,8 +107,16 @@ module ActiveRecord end def intrange_to_string(object) - if Range === object - "[#{object.first},#{object.exclude_end? ? object.last : object.last.to_i + 1})" + if object.nil? + nil + elsif Range === object + if [object.first, object.last].all? { |el| Integer === el } + "[#{object.first.to_i},#{object.exclude_end? ? object.last.to_i : object.last.to_i + 1})" + elsif [object.first, object.last].all? { |el| NilClass === el } + "empty" + else + nil + end else object end |