Skip to content

Method to determine if an event is allowed #25

@cgriego

Description

@cgriego

To support user input validation logic I'm writing, I need the ability to ask a model if it will allow an event to transition. If the event were name "close" then something like "can_close?". Without a method, I've had to reach deep into the internals of stateflow from my model.

  def can_close?
    self.class.machine.events[:close].send(:transitions).select do |transition|
      transition.from.include? current_state.try(:name)
    end.first.try(:can_transition?, self)
  end

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions