lib/tapioca/dsl/compilers/active_model_attributes.rb in tapioca-0.12.0 vs lib/tapioca/dsl/compilers/active_model_attributes.rb in tapioca-0.13.0

- old
+ new

@@ -1,10 +1,12 @@ # typed: strict # frozen_string_literal: true return unless defined?(ActiveModel::Attributes) +require "tapioca/dsl/helpers/active_model_type_helper" + module Tapioca module Dsl module Compilers # `Tapioca::Dsl::Compilers::ActiveModelAttributes` decorates RBI files for all # classes that use [`ActiveModel::Attributes`](https://edgeapi.rubyonrails.org/classes/ActiveModel/Attributes/ClassMethods.html). @@ -97,15 +99,10 @@ HANDLED_METHOD_TARGETS.include?(target.to_s) end sig { params(attribute_type_value: T.untyped).returns(::String) } def type_for(attribute_type_value) - # This guarantees that the type will remain as T.untyped for attributes in the following form: - # attribute :name - # This is because for a generic attribute with no specified type, ActiveModel::Type::Value.new is returned - return "T.untyped" if attribute_type_value.instance_of?(ActiveModel::Type::Value) - type = case attribute_type_value when ActiveModel::Type::Boolean "T::Boolean" when ActiveModel::Type::Date "::Date" @@ -118,10 +115,10 @@ when ActiveModel::Type::Integer "::Integer" when ActiveModel::Type::String "::String" else - attribute_type_value.class.name.to_s + Helpers::ActiveModelTypeHelper.type_for(attribute_type_value) end as_nilable_type(type) end