Class: EndState::Transition
- Inherits:
-
Object
- Object
- EndState::Transition
- Defined in:
- lib/end_state/transition.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#blocked_event_message ⇒ Object
readonly
Returns the value of attribute blocked_event_message.
-
#finalizers ⇒ Object
Returns the value of attribute finalizers.
-
#guards ⇒ Object
Returns the value of attribute guards.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #allowed?(object, params = {}) ⇒ Boolean
- #blocked(message) ⇒ Object
- #custom_action(action) ⇒ Object
- #finalize(object, previous_state, params = {}) ⇒ Object
- #finalizer(finalizer) ⇒ Object
- #guard(guard) ⇒ Object
-
#initialize(state) ⇒ Transition
constructor
A new instance of Transition.
- #persistence_on ⇒ Object
- #will_allow?(object, params = {}) ⇒ Boolean
Constructor Details
#initialize(state) ⇒ Transition
Returns a new instance of Transition.
6 7 8 9 10 11 |
# File 'lib/end_state/transition.rb', line 6 def initialize(state) @state = state @action = Action @guards = [] @finalizers = [] end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'lib/end_state/transition.rb', line 4 def action @action end |
#blocked_event_message ⇒ Object (readonly)
Returns the value of attribute blocked_event_message.
3 4 5 |
# File 'lib/end_state/transition.rb', line 3 def end |
#finalizers ⇒ Object
Returns the value of attribute finalizers.
4 5 6 |
# File 'lib/end_state/transition.rb', line 4 def finalizers @finalizers end |
#guards ⇒ Object
Returns the value of attribute guards.
4 5 6 |
# File 'lib/end_state/transition.rb', line 4 def guards @guards end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
3 4 5 |
# File 'lib/end_state/transition.rb', line 3 def state @state end |
Instance Method Details
#allowed?(object, params = {}) ⇒ Boolean
13 14 15 |
# File 'lib/end_state/transition.rb', line 13 def allowed?(object, params={}) guards.all? { |guard| guard.new(object, state, params).allowed? } end |
#blocked(message) ⇒ Object
45 46 47 |
# File 'lib/end_state/transition.rb', line 45 def blocked() = end |
#custom_action(action) ⇒ Object
29 30 31 |
# File 'lib/end_state/transition.rb', line 29 def custom_action(action) @action = action end |
#finalize(object, previous_state, params = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/end_state/transition.rb', line 21 def finalize(object, previous_state, params={}) finalizers.each_with_object([]) do |finalizer, finalized| finalized << finalizer return rollback(finalized, object, previous_state, params) unless run_finalizer(finalizer, object, state, params) end true end |
#finalizer(finalizer) ⇒ Object
37 38 39 |
# File 'lib/end_state/transition.rb', line 37 def finalizer(finalizer) finalizers << finalizer end |
#guard(guard) ⇒ Object
33 34 35 |
# File 'lib/end_state/transition.rb', line 33 def guard(guard) guards << guard end |
#persistence_on ⇒ Object
41 42 43 |
# File 'lib/end_state/transition.rb', line 41 def persistence_on finalizer Finalizers::Persistence end |
#will_allow?(object, params = {}) ⇒ Boolean
17 18 19 |
# File 'lib/end_state/transition.rb', line 17 def will_allow?(object, params={}) guards.all? { |guard| guard.new(object, state, params).will_allow? } end |