RailsStateMachine 2.2.0 released

  • 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. 5 months ago