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

Add events availability methods #210

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ def workflow(&specification)
assign_workflow Specification.new(Hash.new, &specification)
end

# Returns available events list for specified state
#
# @param [Symbol] State
#
# @return Array[Symbol] List of events
#
def available_workflow_events_for_state(state)
state_spec = self.class.workflow_spec.states[state.to_sym]
raise "Unknown state '#{state}'" if state_spec.nil?

state_spec.events.select do |key, spec|
condition_applicable? self
end
end

# Returns available events list for current state
#
def enabled_workflow_events
current_state.events.map { |k, events| events.select { |e| e.condition_applicable? self } }.flatten.uniq.map(&:name)
end

private

# Creates the convinience methods like `my_transition!`
Expand Down