RailsStateMachine 2.2.0 released

Posted . Visible to the public.
  • Added: State machine can now use the :prefix-option to avoid name collision if you define multiple state machines on the same model, and use state names more than once
    • Previously state_machine-definitions like this:
        class Form
        
          state_machine :first_wizard_stage do
            state :completed
          end
      
          state_machine :second_wizard_stage do
            state :completed
          end
          
        end
      
      would produce the following warning:
        rails_state_machine-2.1.1/lib/rails_state_machine/state_machine.rb:62: warning: already initialized constant Form::STATE_COMPLETED
      
    • This can now be fixed with the :prefix-option:
        class Form
        
          state_machine :first_wizard_stage, prefix: :foo do
            state :completed
          end
      
          state_machine :second_wizard_stage, prefix: :bar do
            state :completed
          end
          
        end
      
    • This defines the following:
      • constants: Form::STATE_FOO_COMPLETED and Form::STATE_BAR_COMPLETE
      • instance methods: #foo_completed? and #bar_completed?
  • Fix bug where additional inclusions of RailsStateMachine::Model would reset previous defined state machines
Max E.
Last edit
Max E.
License
Source code in this card is licensed under the MIT License.
Posted by Max E. to makandra dev (2023-12-07 11:58)