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

Ability to subclass Core::State, Event and Transition to add custom options and DSL #812

Open
marcrohloff opened this issue Feb 12, 2023 · 0 comments

Comments

@marcrohloff
Copy link

Is your feature request related to a problem? Please describe.
My class and dsl would be cleaner if it were possible to add custom dsl and options to event and transition blocks.
For ex

aasm do
  ....
  event :start, metadata: { priority: 0 } do
    requires_arguments :user_id, :reason
    transition from: :idle, to: :running do
      metadata: priority: 1
    end
   end
...

Describe the solution you'd like
For a custom subclass of AASM::Base to be able to set the sub-class of AASM::Core::State, Event and Transition to instantiate. At a quick glance it looks like it would also be necessary to make a way to customize the valid_keys lists passed to add_options_from_dsl

Describe alternatives you've considered
It is possible to implement the features directly in the implementing class but it quickly gets messy. For ex

aasm do 
...
event :start do
  before ->(**args) { check_arguments!(args, [:user_id, :reason]) }
...  
end # aasm

def check_arguments!(args, required_keys)
raise "Missing arguments" unless (required_keys - args.keys).blank?
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant