Module: Transitionable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/transitionable.rb,
lib/transitionable/version.rb
Defined Under Namespace
Modules: ClassMethods
Classes: InvalidStateTransition
Constant Summary
collapse
- VERSION =
"0.3.2"
Instance Method Summary
collapse
Instance Method Details
#validate_transition(target_state:) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/transitionable.rb', line 43
def validate_transition(target_state:)
self.class.state_machines.each do |machine_name, machine|
next unless machine[:states].include?(target_state)
current_state = send(machine_name)
matched_transition = machine[:transitions].detect do |transition|
transition[:from] == current_state && transition[:to] == target_state
end
return true if matched_transition.present?
yield(InvalidStateTransition.new(current_state, target_state)) if block_given?
return false
end
raise InvalidStateTransition.new(nil, target_state)
end
|
#validate_transition!(target_state:) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/transitionable.rb', line 35
def validate_transition!(target_state:)
current_state = current_state_based_on(target_state)
unless validate_transition(target_state: target_state)
raise InvalidStateTransition.new(current_state, target_state)
end
true
end
|