aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-04-12 21:27:12 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-04-12 22:03:23 +0900
commit59d32a6eab144b808bdd9d96b6e6c2dc32e66f32 (patch)
treea204d84385a731731fbe363606b9d97c3748f019 /activerecord/lib/active_record/connection_adapters/postgresql
parent3bd534287139549cee10e10364344d66139d9237 (diff)
downloadrails-59d32a6eab144b808bdd9d96b6e6c2dc32e66f32.tar.gz
rails-59d32a6eab144b808bdd9d96b6e6c2dc32e66f32.tar.bz2
rails-59d32a6eab144b808bdd9d96b6e6c2dc32e66f32.zip
Refactor around sql_type metadata and column
* remove useless `@type_metadata` and `@array` * move the compatibility code (for array) into column * etc.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/column.rb12
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb51
3 files changed, 34 insertions, 31 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
index ef98d2b37a..ec25bb1e19 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
@@ -4,8 +4,7 @@ module ActiveRecord
module ConnectionAdapters
module PostgreSQL
class Column < ConnectionAdapters::Column # :nodoc:
- delegate :array, :oid, :fmod, to: :sql_type_metadata
- alias :array? :array
+ delegate :oid, :fmod, to: :sql_type_metadata
def initialize(*, serial: nil, **)
super
@@ -15,6 +14,15 @@ module ActiveRecord
def serial?
@serial
end
+
+ def array
+ sql_type_metadata.sql_type.end_with?("[]")
+ end
+ alias :array? :array
+
+ def sql_type
+ super.sub(/\[\]\z/, "")
+ end
end
end
PostgreSQLColumn = PostgreSQL::Column # :nodoc:
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
index c412d1f34c..2a641cbe53 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -675,7 +675,7 @@ module ActiveRecord
precision: cast_type.precision,
scale: cast_type.scale,
)
- PostgreSQLTypeMetadata.new(simple_type, oid: oid, fmod: fmod)
+ PostgreSQL::TypeMetadata.new(simple_type, oid: oid, fmod: fmod)
end
def sequence_name_from_parts(table_name, column_name, suffix)
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb b/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb
index 403b3ead98..8bdec623af 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb
@@ -3,39 +3,34 @@
module ActiveRecord
# :stopdoc:
module ConnectionAdapters
- class PostgreSQLTypeMetadata < DelegateClass(SqlTypeMetadata)
- undef to_yaml if method_defined?(:to_yaml)
+ module PostgreSQL
+ class TypeMetadata < DelegateClass(SqlTypeMetadata)
+ undef to_yaml if method_defined?(:to_yaml)
- attr_reader :oid, :fmod, :array
+ attr_reader :oid, :fmod
- def initialize(type_metadata, oid: nil, fmod: nil)
- super(type_metadata)
- @type_metadata = type_metadata
- @oid = oid
- @fmod = fmod
- @array = /\[\]$/.match?(type_metadata.sql_type)
- end
-
- def sql_type
- super.gsub(/\[\]$/, "")
- end
+ def initialize(type_metadata, oid: nil, fmod: nil)
+ super(type_metadata)
+ @oid = oid
+ @fmod = fmod
+ end
- def ==(other)
- other.is_a?(PostgreSQLTypeMetadata) &&
- __getobj__ == other.__getobj__ &&
- oid == other.oid &&
- fmod == other.fmod &&
- array == other.array
- end
- alias eql? ==
+ def ==(other)
+ other.is_a?(TypeMetadata) &&
+ __getobj__ == other.__getobj__ &&
+ oid == other.oid &&
+ fmod == other.fmod
+ end
+ alias eql? ==
- def hash
- PostgreSQLTypeMetadata.hash ^
- __getobj__.hash ^
- oid.hash ^
- fmod.hash ^
- array.hash
+ def hash
+ TypeMetadata.hash ^
+ __getobj__.hash ^
+ oid.hash ^
+ fmod.hash
+ end
end
end
+ PostgreSQLTypeMetadata = PostgreSQL::TypeMetadata
end
end