Skip to content
Draft
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
8 changes: 4 additions & 4 deletions lib/tapioca/dsl/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def add_error(error)
def parameters_types_from_signature(method_def, signature)
params = [] #: Array[String]

return method_def.parameters.map { "T.untyped" } unless signature
return method_def.parameters.map { "::T.untyped" } unless signature

# parameters types
signature.arg_types.each { |arg_type| params << arg_type[1].to_s }
Expand Down Expand Up @@ -171,13 +171,13 @@ def compile_method_parameters_to_rbi(method_def)
when :req
create_param(name, type: method_type)
when :opt
create_opt_param(name, type: method_type, default: "T.unsafe(nil)")
create_opt_param(name, type: method_type, default: "::T.unsafe(nil)")
when :rest
create_rest_param(name, type: method_type)
when :keyreq
create_kw_param(name, type: method_type)
when :key
create_kw_opt_param(name, type: method_type, default: "T.unsafe(nil)")
create_kw_opt_param(name, type: method_type, default: "::T.unsafe(nil)")
when :keyrest
create_kw_rest_param(name, type: method_type)
when :block
Expand All @@ -191,7 +191,7 @@ def compile_method_parameters_to_rbi(method_def)
#: ((Method | UnboundMethod) method_def) -> String
def compile_method_return_type_to_rbi(method_def)
signature = signature_of(method_def)
return_type = signature.nil? ? "T.untyped" : name_of_type(signature.return_type)
return_type = signature.nil? ? "::T.untyped" : name_of_type(signature.return_type)
sanitize_signature_types(return_type)
end
end
Expand Down
38 changes: 19 additions & 19 deletions lib/tapioca/dsl/compilers/aasm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ def decorate
name = state.name
name = "#{namespace}_#{name}" if namespace

model.create_constant("STATE_#{name.upcase}", value: "T.let(T.unsafe(nil), Symbol)")
model.create_method("#{name}?", return_type: "T::Boolean")
model.create_constant("STATE_#{name.upcase}", value: "::T.let(::T.unsafe(nil), Symbol)")
model.create_method("#{name}?", return_type: "::T::Boolean")
end

# Create all of the methods for each event
parameters = [create_rest_param("opts", type: "T.untyped")]
parameters = [create_rest_param("opts", type: "::T.untyped")]
state_machine.events.each do |event|
model.create_method(event.name.to_s, parameters: parameters)
model.create_method("#{event.name}!", parameters: parameters)
model.create_method("#{event.name}_without_validation!", parameters: parameters)
model.create_method("may_#{event.name}?", return_type: "T::Boolean")
model.create_method("may_#{event.name}?", return_type: "::T::Boolean")

# For events, if there's a namespace the default methods are created in addition to
# namespaced ones.
Expand All @@ -105,7 +105,7 @@ def decorate

model.create_method(name.to_s, parameters: parameters)
model.create_method("#{name}!", parameters: parameters)
model.create_method("may_#{name}?", return_type: "T::Boolean")
model.create_method("may_#{name}?", return_type: "::T::Boolean")

# There's no namespaced method created for `_without_validation`, so skip
# defining a method for:
Expand All @@ -118,8 +118,8 @@ def decorate
model.create_method(
"aasm",
parameters: [
create_rest_param("args", type: "T.untyped"),
create_block_param("block", type: "T.nilable(T.proc.bind(PrivateAASMMachine).void)"),
create_rest_param("args", type: "::T.untyped"),
create_block_param("block", type: "::T.nilable(::T.proc.bind(PrivateAASMMachine).void)"),
],
return_type: "PrivateAASMMachine",
class_method: true,
Expand All @@ -132,9 +132,9 @@ def decorate
machine.create_method(
"event",
parameters: [
create_param("name", type: "T.untyped"),
create_opt_param("options", default: "nil", type: "T.untyped"),
create_block_param("block", type: "T.proc.bind(PrivateAASMEvent).void"),
create_param("name", type: "::T.untyped"),
create_opt_param("options", default: "nil", type: "::T.untyped"),
create_block_param("block", type: "::T.proc.bind(PrivateAASMEvent).void"),
],
)

Expand All @@ -144,8 +144,8 @@ def decorate
machine.create_method(
method,
parameters: [
create_rest_param("callbacks", type: "T.any(String, Symbol, T::Class[T.anything], Proc)"),
create_block_param("block", type: "T.nilable(T.proc.bind(#{constant_name}).void)"),
create_rest_param("callbacks", type: "::T.any(String, Symbol, ::T::Class[::T.anything], Proc)"),
create_block_param("block", type: "::T.nilable(::T.proc.bind(#{constant_name}).void)"),
],
)
end
Expand All @@ -158,10 +158,10 @@ def decorate
event.create_method(
method,
parameters: [
create_opt_param("symbol", type: "T.nilable(Symbol)", default: "nil"),
create_opt_param("symbol", type: "::T.nilable(Symbol)", default: "nil"),
create_block_param(
"block",
type: "T.nilable(T.proc.bind(#{constant_name}).params(opts: T.untyped).void)",
type: "::T.nilable(::T.proc.bind(#{constant_name}).params(opts: ::T.untyped).void)",
),
],
)
Expand All @@ -170,23 +170,23 @@ def decorate
event.create_method(
"transitions",
parameters: [
create_opt_param("definitions", default: "nil", type: "T.untyped"),
create_block_param("block", type: "T.nilable(T.proc.bind(PrivateAASMTransition).void)"),
create_opt_param("definitions", default: "nil", type: "::T.untyped"),
create_block_param("block", type: "::T.nilable(::T.proc.bind(PrivateAASMTransition).void)"),
],
)
end

machine.create_class("PrivateAASMTransition", superclass_name: "AASM::Core::Transition") do |transition|
TRANSITION_CALLBACKS.each do |method|
return_type = "T.untyped"
return_type = "T::Boolean" if method == "guard"
return_type = "::T.untyped"
return_type = "::T::Boolean" if method == "guard"

transition.create_method(
method,
parameters: [
create_block_param(
"block",
type: "T.nilable(T.proc.bind(#{constant_name}).params(opts: T.untyped).void)",
type: "::T.nilable(::T.proc.bind(#{constant_name}).params(opts: ::T.untyped).void)",
),
],
return_type: return_type,
Expand Down
8 changes: 4 additions & 4 deletions lib/tapioca/dsl/compilers/action_controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ def create_unknown_proxy_method(helper_methods, method_name)
helper_methods.create_method(
method_name.to_s,
parameters: [
create_rest_param("args", type: "T.untyped"),
create_kw_rest_param("kwargs", type: "T.untyped"),
create_block_param("blk", type: "T.untyped"),
create_rest_param("args", type: "::T.untyped"),
create_kw_rest_param("kwargs", type: "::T.untyped"),
create_block_param("blk", type: "::T.untyped"),
],
return_type: "T.untyped",
return_type: "::T.untyped",
)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/tapioca/dsl/compilers/action_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ def decorate
)
scope.create_method(
"#{name}?",
return_type: "T::Boolean",
return_type: "::T::Boolean",
)
scope.create_method(
"#{name}=",
parameters: [create_param("value", type: "T.nilable(T.any(#{type}, String))")],
return_type: "T.untyped",
parameters: [create_param("value", type: "::T.nilable(::T.any(#{type}, String))")],
return_type: "::T.untyped",
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tapioca/dsl/compilers/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def decorate
job.create_method(
"perform_later",
parameters: perform_later_parameters(parameters, constant_name),
return_type: "T.any(#{constant_name}, FalseClass)",
return_type: "::T.any(#{constant_name}, FalseClass)",
class_method: true,
)

Expand All @@ -75,7 +75,7 @@ def perform_later_parameters(parameters, constant_name)
parameters.reject! { |typed_param| RBI::BlockParam === typed_param.param }
parameters + [create_block_param(
"block",
type: "T.nilable(T.proc.params(job: #{constant_name}).void)",
type: "::T.nilable(::T.proc.params(job: #{constant_name}).void)",
)]
else
parameters
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_model_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def handle_method_pattern?(pattern)
def type_for(attribute_type_value)
case attribute_type_value
when ActiveModel::Type::Boolean
as_nilable_type("T::Boolean")
as_nilable_type("::T::Boolean")
when ActiveModel::Type::Date
as_nilable_type("::Date")
when ActiveModel::Type::DateTime, ActiveModel::Type::Time
Expand Down
4 changes: 2 additions & 2 deletions lib/tapioca/dsl/compilers/active_model_secure_password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def decorate
if method == :authenticate || method.start_with?("authenticate_")
klass.create_method(
method.to_s,
parameters: [create_param("unencrypted_password", type: "T.untyped")],
return_type: "T.any(#{constant}, FalseClass)",
parameters: [create_param("unencrypted_password", type: "::T.untyped")],
return_type: "::T.any(#{constant}, FalseClass)",
)
else
create_method_from_def(klass, constant.instance_method(method))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def decorate
# Create RBI definitions for all the attributes that use confirmation validation
confirmation_validators.each do |validator|
validator.attributes.each do |attr_name|
klass.create_method("#{attr_name}_confirmation", return_type: "T.untyped")
klass.create_method("#{attr_name}_confirmation", return_type: "::T.untyped")
klass.create_method(
"#{attr_name}_confirmation=",
parameters: [create_param("#{attr_name}_confirmation", type: "T.untyped")],
return_type: "T.untyped",
parameters: [create_param("#{attr_name}_confirmation", type: "::T.untyped")],
return_type: "::T.untyped",
)
end
end
Expand Down
32 changes: 16 additions & 16 deletions lib/tapioca/dsl/compilers/active_record_associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def populate_nested_attribute_writers(mod)
constant.nested_attributes_options.keys.each do |association_name|
mod.create_method(
"#{association_name}_attributes=",
parameters: [create_param("attributes", type: "T.untyped")],
return_type: "T.untyped",
parameters: [create_param("attributes", type: "::T.untyped")],
return_type: "::T.untyped",
)
end
end
Expand Down Expand Up @@ -200,37 +200,37 @@ def populate_single_assoc_getter_setter(klass, association_name, reflection)
if association_methods_module.method_defined?("#{association_name}_changed?")
klass.create_method(
"#{association_name}_changed?",
return_type: "T::Boolean",
return_type: "::T::Boolean",
)
end
if association_methods_module.method_defined?("#{association_name}_previously_changed?")
klass.create_method(
"#{association_name}_previously_changed?",
return_type: "T::Boolean",
return_type: "::T::Boolean",
)
end
unless reflection.polymorphic?
klass.create_method(
"build_#{association_name}",
parameters: [
create_rest_param("args", type: "T.untyped"),
create_block_param("blk", type: "T.untyped"),
create_rest_param("args", type: "::T.untyped"),
create_block_param("blk", type: "::T.untyped"),
],
return_type: association_class,
)
klass.create_method(
"create_#{association_name}",
parameters: [
create_rest_param("args", type: "T.untyped"),
create_block_param("blk", type: "T.untyped"),
create_rest_param("args", type: "::T.untyped"),
create_block_param("blk", type: "::T.untyped"),
],
return_type: association_class,
)
klass.create_method(
"create_#{association_name}!",
parameters: [
create_rest_param("args", type: "T.untyped"),
create_block_param("blk", type: "T.untyped"),
create_rest_param("args", type: "::T.untyped"),
create_block_param("blk", type: "::T.untyped"),
],
return_type: association_class,
)
Expand All @@ -249,25 +249,25 @@ def populate_collection_assoc_getter_setter(klass, association_name, reflection)
)
klass.create_method(
"#{association_name}=",
parameters: [create_param("value", type: "T::Enumerable[#{association_class}]")],
parameters: [create_param("value", type: "::T::Enumerable[#{association_class}]")],
return_type: "void",
)
klass.create_method(
"#{association_name.to_s.singularize}_ids",
return_type: "T::Array[T.untyped]",
return_type: "::T::Array[::T.untyped]",
)
klass.create_method(
"#{association_name.to_s.singularize}_ids=",
parameters: [create_param("ids", type: "T::Array[T.untyped]")],
return_type: "T::Array[T.untyped]",
parameters: [create_param("ids", type: "::T::Array[::T.untyped]")],
return_type: "::T::Array[::T.untyped]",
)
end

#: (ReflectionType reflection) -> String
def type_for(reflection)
validate_reflection!(reflection)

return "T.untyped" if !constant.table_exists? || polymorphic_association?(reflection)
return "::T.untyped" if !constant.table_exists? || polymorphic_association?(reflection)

T.must(qualified_name_of(reflection.klass))
end
Expand Down Expand Up @@ -364,7 +364,7 @@ def relation_type_for(reflection)
"#{qualified_name_of(reflection.klass)}::#{AssociationsCollectionProxyClassName}"
end
elsif polymorphic_association
"ActiveRecord::Associations::CollectionProxy[T.untyped]"
"ActiveRecord::Associations::CollectionProxy[::T.untyped]"
else
"::ActiveRecord::Associations::CollectionProxy[#{qualified_name_of(reflection.klass)}]"
end
Expand Down
Loading
Loading