From 58ef84b78bb9a51efcc22a19667e7496b5e364e6 Mon Sep 17 00:00:00 2001 From: Ufuk Kayserilioglu Date: Thu, 18 Apr 2024 21:49:46 +0000 Subject: [PATCH] Minor fixes to the Tapioca DSL compiler This commit fixes a couple of issues with the Tapioca DSL compiler: 1. We have to check for the existance of the `Measured::Rails` class and not `Measured::Rails::ActiveRecord` since the latter might not have been loaded yet by the time we do the check for the constant. 2. It is better and safer to use the qualified name of the field class type for using inside signatures, so that we have `::Measured::Length` instead of `Measured::Length`. --- lib/tapioca/dsl/compilers/measured_rails.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/tapioca/dsl/compilers/measured_rails.rb b/lib/tapioca/dsl/compilers/measured_rails.rb index 7bf8ad2..e5cd47f 100644 --- a/lib/tapioca/dsl/compilers/measured_rails.rb +++ b/lib/tapioca/dsl/compilers/measured_rails.rb @@ -1,7 +1,7 @@ # typed: strict # frozen_string_literal: true -return unless defined?(::Measured::Rails::ActiveRecord) +return unless defined?(::Measured::Rails) module Tapioca module Dsl @@ -88,16 +88,18 @@ def self.gather_constants sig { params(model: RBI::Scope).void } def populate_measured_methods(model) constant.measured_fields.each do |field, attrs| - klass = attrs[:class].to_s + class_name = qualified_name_of(attrs[:class]) + + next unless class_name model.create_method( field.to_s, - return_type: as_nilable_type(klass) + return_type: as_nilable_type(class_name) ) model.create_method( "#{field}=", - parameters: [create_param("value", type: as_nilable_type(klass))], + parameters: [create_param("value", type: as_nilable_type(class_name))], return_type: "void" ) end