Skip to content

Commit

Permalink
add extended state machines compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
stathis-alexander committed Sep 22, 2024
1 parent 6735573 commit 4e92728
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
boba (0.0.2)
boba (0.0.5)
sorbet-static-and-runtime (~> 0.5)
tapioca (~> 0.16.2)

Expand Down
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Boba History

## 0.0.5

- Add extended state machines compiler to fix typing on state machines class methods

## 0.0.4

- Add railtie to make `PrivateRelation` type available at runtime
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ clean:
docs:
bundle exec rake generate_dsl_documentation


# release
# make clean && make build
# make clean && make docs && make build
# gem push boba-[version].gem
# gh release create [version]
2 changes: 1 addition & 1 deletion lib/boba/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# frozen_string_literal: true

module Boba
VERSION = "0.0.4"
VERSION = "0.0.5"
end
37 changes: 37 additions & 0 deletions lib/tapioca/dsl/compilers/state_machines_extended.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# typed: ignore
# frozen_string_literal: true

return unless defined?(Tapioca)

require "tapioca/dsl/compilers/state_machines"

module Tapioca
module Dsl
module Compilers
# `Tapioca::Dsl::Compilers::StateMachinesExtended` extends the default state machines compiler provided by Tapioca
# to allow for calling `with_state` and `without_state` on all Active Record relations. This is a temporary fix
# until a more durable solution can be found for this type of issue.
# See https://github.com/Shopify/tapioca/pull/1994#issuecomment-2302624697.
class StateMachinesExtended < ::Tapioca::Dsl::Compilers::StateMachines
ACTIVE_RECORD_RELATION_MODULE_NAMES = [
"GeneratedRelationMethods",
"GeneratedAssociationRelationMethods",
].freeze

def decorate
return if constant.state_machines.empty?

super()

root.create_path(T.unsafe(constant)) do |klass|
class_module_name = "StateMachineClassHelperModule"

ACTIVE_RECORD_RELATION_MODULE_NAMES.each do |module_name|
klass.create_module(module_name).create_include(class_module_name)
end
end
end
end
end
end
end
6 changes: 6 additions & 0 deletions manual/compiler_statemachinesextended.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## StateMachinesExtended

`Tapioca::Dsl::Compilers::StateMachinesExtended` extends the default state machines compiler provided by Tapioca
to allow for calling `with_state` and `without_state` on all Active Record relations. This is a temporary fix
until a more durable solution can be found for this type of issue.
See https://github.com/Shopify/tapioca/pull/1994#issuecomment-2302624697.
1 change: 1 addition & 0 deletions manual/compilers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ This list is an evergeen list of currently available compilers.
* [ActiveRecordAssociationsPersisted](compiler_activerecordassociationspersisted.md)
* [ActiveRecordColumnsPersisted](compiler_activerecordcolumnspersisted.md)
* [MoneyRails](compiler_moneyrails.md)
* [StateMachinesExtended](compiler_statemachinesextended.md)
<!-- END_COMPILER_LIST -->

0 comments on commit 4e92728

Please sign in to comment.