Skip to content

Commit 58ef84b

Browse files
committed
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`.
1 parent 36f2353 commit 58ef84b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/tapioca/dsl/compilers/measured_rails.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# typed: strict
22
# frozen_string_literal: true
33

4-
return unless defined?(::Measured::Rails::ActiveRecord)
4+
return unless defined?(::Measured::Rails)
55

66
module Tapioca
77
module Dsl
@@ -88,16 +88,18 @@ def self.gather_constants
8888
sig { params(model: RBI::Scope).void }
8989
def populate_measured_methods(model)
9090
constant.measured_fields.each do |field, attrs|
91-
klass = attrs[:class].to_s
91+
class_name = qualified_name_of(attrs[:class])
92+
93+
next unless class_name
9294

9395
model.create_method(
9496
field.to_s,
95-
return_type: as_nilable_type(klass)
97+
return_type: as_nilable_type(class_name)
9698
)
9799

98100
model.create_method(
99101
"#{field}=",
100-
parameters: [create_param("value", type: as_nilable_type(klass))],
102+
parameters: [create_param("value", type: as_nilable_type(class_name))],
101103
return_type: "void"
102104
)
103105
end

0 commit comments

Comments
 (0)