Skip to content

Commit

Permalink
Generate a module with shale methods in the RBI
Browse files Browse the repository at this point in the history
  • Loading branch information
Verseth committed May 13, 2024
1 parent 3f3b3b8 commit c2d0796
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/tapioca/dsl/compilers/shale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ def gather_constants
end
end

SHALE_ATTRIBUTE_MODULE = 'ShaleAttributeMethods'

sig { override.void }
def decorate
# Create a RBI definition for each class that inherits from Shale::Mapper
root.create_path(constant) do |klass|
has_shale_builder = includes_shale_builder(constant)

mod = klass.create_module(SHALE_ATTRIBUTE_MODULE)
klass.create_include(SHALE_ATTRIBUTE_MODULE)
# For each attribute defined in the class
constant.attributes.each_value do |attribute|
attribute = T.let(attribute, ::Shale::Attribute)
Expand All @@ -55,18 +58,18 @@ def decorate
parameters: { block: "T.proc.params(arg0: #{non_nilable_type}).void" },
return_type: non_nilable_type
)
klass.create_method_with_sigs(
mod.create_method_with_sigs(
attribute.name,
sigs: sigs,
comments: comments,
parameters: [RBI::BlockParam.new('block')],
)
else
klass.create_method(attribute.name, return_type: type, comments: comments)
mod.create_method(attribute.name, return_type: type, comments: comments)
end

# setter
klass.create_method(
mod.create_method(
"#{attribute.name}=",
parameters: [create_param('value', type: type)],
return_type: type,
Expand Down

0 comments on commit c2d0796

Please sign in to comment.