aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-05-17 12:24:13 -0600
committerSean Griffin <sean@thoughtbot.com>2014-05-19 08:07:21 -0700
commit0b682e4b05c8f58c77c655650af6638c483ac903 (patch)
treee22d197ed7d828dad7f249d8878a8fb8cff1ebd2 /activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
parenta0eec57ef0fbbbb2910a46ca65bd5b565ca0534c (diff)
downloadrails-0b682e4b05c8f58c77c655650af6638c483ac903.tar.gz
rails-0b682e4b05c8f58c77c655650af6638c483ac903.tar.bz2
rails-0b682e4b05c8f58c77c655650af6638c483ac903.zip
Delegate `Column#type` to the injected type object
The decision to wrap type registrations in a proc was made for two reasons. 1. Some cases need to make an additional decision based on the type (e.g. a `Decimal` with a 0 scale) 2. Aliased types are automatically updated if they type they point to is updated later. If a user or another adapter decides to change the object used for `decimal` columns, `numeric`, and `number` will automatically point to the new type, without having to track what types are aliased explicitly. Everything else here should be pretty straightforward. PostgreSQL ranges had to change slightly, since the `simplified_type` method is gone.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid.rb13
1 files changed, 5 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
index a97c33ae6f..90bf6c6d1a 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
@@ -2,10 +2,7 @@ module ActiveRecord
module ConnectionAdapters
module PostgreSQL
module OID # :nodoc:
- class Type
- def type; end
- def simplified_type(sql_type); type end
-
+ class Type < Type::Value
def infinity(options = {})
::Float::INFINITY * (options[:negative] ? -1 : 1)
end
@@ -136,11 +133,11 @@ module ActiveRecord
end
class Range < Type
- attr_reader :subtype
- def simplified_type(sql_type); sql_type.to_sym end
+ attr_reader :subtype, :type
- def initialize(subtype)
+ def initialize(subtype, type)
@subtype = subtype
+ @type = type
end
def extract_bounds(value)
@@ -412,7 +409,7 @@ This is not reliable and will be removed in the future.
def register_range_type(row)
if subtype = @store[row['rngsubtype'].to_i]
- register row['oid'], OID::Range.new(subtype)
+ register row['oid'], OID::Range.new(subtype, row['typname'].to_sym)
end
end