Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for AASM compiler #2043

Merged
merged 1 commit into from
Oct 17, 2024
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
42 changes: 41 additions & 1 deletion lib/tapioca/dsl/compilers/aasm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ class AASM < Compiler
T::Array[String],
)

TRANSITION_CALLBACKS =
T.let(
[
"on_transition",
"guard",
"after",
"success",
].freeze,
T::Array[String],
)

ConstantType = type_member { { fixed: T.all(T::Class[::AASM], ::AASM::ClassMethods) } }

sig { override.void }
Expand Down Expand Up @@ -162,8 +173,37 @@ def decorate
method,
parameters: [
create_opt_param("symbol", type: "T.nilable(Symbol)", default: "nil"),
create_block_param("block", type: "T.nilable(T.proc.bind(#{constant_name}).void)"),
create_block_param(
"block",
type: "T.nilable(T.proc.bind(#{constant_name}).params(opts: T.untyped).void)",
),
],
)
end

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)"),
],
)
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"

transition.create_method(
method,
parameters: [
create_block_param(
"block",
type: "T.nilable(T.proc.bind(#{constant_name}).params(opts: T.untyped).void)",
),
],
return_type: return_type,
)
end
end
Expand Down
105 changes: 78 additions & 27 deletions spec/tapioca/dsl/compilers/aasm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,49 @@ def error_on_all_events(*callbacks, &block); end
def event(name, options = nil, &block); end

class PrivateAASMEvent < AASM::Core::Event
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after_commit(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after_transaction(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def before(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def before_success(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def before_transaction(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def ensure(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def error(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def success(symbol = nil, &block); end

sig { params(definitions: T.untyped, block: T.nilable(T.proc.bind(PrivateAASMTransition).void)).returns(T.untyped) }
def transitions(definitions = nil, &block); end
end

class PrivateAASMTransition < AASM::Core::Transition
sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after(&block); end

sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T::Boolean) }
def guard(&block); end

sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def on_transition(&block); end

sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def success(&block); end
end
end

Expand Down Expand Up @@ -249,32 +266,49 @@ def error_on_all_events(*callbacks, &block); end
def event(name, options = nil, &block); end

class PrivateAASMEvent < AASM::Core::Event
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after_commit(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after_transaction(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def before(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def before_success(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def before_transaction(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def ensure(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def error(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def success(symbol = nil, &block); end

sig { params(definitions: T.untyped, block: T.nilable(T.proc.bind(PrivateAASMTransition).void)).returns(T.untyped) }
def transitions(definitions = nil, &block); end
end

class PrivateAASMTransition < AASM::Core::Transition
sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after(&block); end

sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T::Boolean) }
def guard(&block); end

sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def on_transition(&block); end

sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def success(&block); end
end
end

Expand Down Expand Up @@ -376,32 +410,49 @@ def error_on_all_events(*callbacks, &block); end
def event(name, options = nil, &block); end

class PrivateAASMEvent < AASM::Core::Event
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after_commit(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after_transaction(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def before(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def before_success(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def before_transaction(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def ensure(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def error(symbol = nil, &block); end

sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).void)).returns(T.untyped) }
sig { params(symbol: T.nilable(Symbol), block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def success(symbol = nil, &block); end

sig { params(definitions: T.untyped, block: T.nilable(T.proc.bind(PrivateAASMTransition).void)).returns(T.untyped) }
def transitions(definitions = nil, &block); end
end

class PrivateAASMTransition < AASM::Core::Transition
sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def after(&block); end

sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T::Boolean) }
def guard(&block); end

sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def on_transition(&block); end

sig { params(block: T.nilable(T.proc.bind(StateMachine).params(opts: T.untyped).void)).returns(T.untyped) }
def success(&block); end
end
end

Expand Down
Loading