diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-17 11:00:06 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-17 11:00:06 -0800 |
commit | cc74088c6cd4da7d3ce7bc0d66c4cae509693622 (patch) | |
tree | bd96188f25c7149155294c87316b3c90bcdc59d9 /activerecord/lib/active_record/connection_adapters/postgresql/cast.rb | |
parent | 75ba92e993d13bf3dffa56f06a72f07dad44b4a6 (diff) | |
parent | 9a4a095ed7ea6f0f65cc9e3bf3258cbdd0ddc210 (diff) | |
download | rails-cc74088c6cd4da7d3ce7bc0d66c4cae509693622.tar.gz rails-cc74088c6cd4da7d3ce7bc0d66c4cae509693622.tar.bz2 rails-cc74088c6cd4da7d3ce7bc0d66c4cae509693622.zip |
Merge pull request #8528 from le0pard/fixed_ar_intrange
AR supporting new int4range and int8range data type on PostgreSQL >= 9.2
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/cast.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/cast.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb index c04a799b8d..3772f7ddaa 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb @@ -92,6 +92,29 @@ module ActiveRecord parse_pg_array(string).map{|val| oid.type_cast val} end + def string_to_intrange(string) + if string.nil? + nil + elsif "empty" == string + (nil..nil) + 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) + else + string + end + end + + def intrange_to_string(object) + if Range === object + "[#{object.first},#{object.exclude_end? ? object.last : object.last.to_i + 1})" + else + object + end + end + private HstorePair = begin |