Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions lib/tapioca/dsl/compilers/active_support_current_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def decorate
current_attributes_methods_name = "GeneratedAttributeMethods"
current_attributes.create_module(current_attributes_methods_name) do |generated_attribute_methods|
dynamic_methods.each do |method|
method = method.to_s
method = constant.instance_method(method)
# We want to generate each method both on the class
generate_method(current_attributes, method, class_method: true)
create_method_from_def(current_attributes, method, class_method: true)
# and on the instance
generate_method(generated_attribute_methods, method, class_method: false)
create_method_from_def(generated_attribute_methods, method, class_method: false)
end

instance_methods.each do |method|
Expand Down Expand Up @@ -110,17 +110,6 @@ def dynamic_methods_of_constant
def instance_methods_of_constant
constant.instance_methods(false)
end

#: (RBI::Scope klass, String method, class_method: bool) -> void
def generate_method(klass, method, class_method:)
method_def = if class_method
constant.method(method)
else
constant.instance_method(method)
end

create_method_from_def(klass, method_def, class_method: class_method)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,52 @@ def account=(value); end

assert_equal(expected, rbi_for(:Current))
end

it "copies types from instance methods to class methods" do
add_ruby_file("current.rb", <<~RUBY)
class Current < ActiveSupport::CurrentAttributes
extend T::Sig

attribute :user_id

sig { returns(T.nilable(Integer)) }
def user_id
super
end

sig { params(value: T.nilable(Integer)).void }
def user_id=(value)
super
end
end
RUBY

expected = <<~RBI
# typed: strong

class Current
include GeneratedAttributeMethods

class << self
sig { returns(T.nilable(::Integer)) }
def user_id; end

sig { params(value: T.nilable(::Integer)).void }
def user_id=(value); end
end

module GeneratedAttributeMethods
sig { returns(T.nilable(::Integer)) }
def user_id; end

sig { params(value: T.nilable(::Integer)).void }
def user_id=(value); end
end
end
RBI

assert_equal(expected, rbi_for(:Current))
end
end
end
end
Expand Down
Loading