Skip to content

Commit

Permalink
Merge pull request #1928 from Shopify/ko/encryption
Browse files Browse the repository at this point in the history
Check for constant definition before invoking
  • Loading branch information
KaanOzkan committed Jun 18, 2024
2 parents 9dd3931 + d741d3d commit 126920b
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions lib/tapioca/dsl/helpers/active_record_column_type_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ def column_type_for(column_name)
sig { params(column_type: T.untyped).returns(String) }
def type_for_activerecord_value(column_type)
case column_type
when defined?(MoneyColumn) && MoneyColumn::ActiveRecordType
when ->(type) { defined?(MoneyColumn) && MoneyColumn::ActiveRecordType === type }
"::Money"
when ActiveRecord::Type::Integer
"::Integer"
when ActiveRecord::Encryption::EncryptedAttributeType
when ->(type) {
defined?(ActiveRecord::Encryption) && ActiveRecord::Encryption::EncryptedAttributeType === type
}
# Reflect to see if `ActiveModel::Type::Value` is being used first.
getter_type = Tapioca::Dsl::Helpers::ActiveModelTypeHelper.type_for(column_type)
return getter_type unless getter_type == "T.untyped"
Expand All @@ -128,20 +130,30 @@ def type_for_activerecord_value(column_type)
"::String"
when ActiveRecord::Type::Serialized
serialized_column_type(column_type)
when defined?(ActiveRecord::Normalization::NormalizedValueType) &&
ActiveRecord::Normalization::NormalizedValueType
when ->(type) {
defined?(ActiveRecord::Normalization::NormalizedValueType) &&
ActiveRecord::Normalization::NormalizedValueType === type
}
type_for_activerecord_value(column_type.cast_type)
when defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Uuid) &&
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Uuid
when ->(type) {
defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Uuid) &&
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Uuid === type
}
"::String"
when defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cidr) &&
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cidr
when ->(type) {
defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cidr) &&
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cidr === type
}
"::IPAddr"
when defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Hstore) &&
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Hstore
when ->(type) {
defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Hstore) &&
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Hstore === type
}
"T::Hash[::String, ::String]"
when defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array) &&
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array
when ->(type) {
defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array) &&
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array === type
}
"T::Array[#{type_for_activerecord_value(column_type.subtype)}]"
else
ActiveModelTypeHelper.type_for(column_type)
Expand Down

0 comments on commit 126920b

Please sign in to comment.