Skip to content

Commit

Permalink
Minor fixes to the Tapioca DSL compiler
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
paracycle committed Apr 18, 2024
1 parent 36f2353 commit 58ef84b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/tapioca/dsl/compilers/measured_rails.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 58ef84b

Please sign in to comment.