Class: EndState::Transition
- Inherits:
-
Object
- Object
- EndState::Transition
- Defined in:
- lib/end_state/transition.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#previous_state ⇒ Object
readonly
Returns the value of attribute previous_state.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #allowed?(params = {}) ⇒ Boolean
- #call(params = {}) ⇒ Object
-
#initialize(object, previous_state, state, configuration, mode) ⇒ Transition
constructor
A new instance of Transition.
- #will_allow?(params = {}) ⇒ Boolean
Constructor Details
#initialize(object, previous_state, state, configuration, mode) ⇒ Transition
Returns a new instance of Transition.
5 6 7 8 9 10 11 |
# File 'lib/end_state/transition.rb', line 5 def initialize(object, previous_state, state, configuration, mode) @object = object @previous_state = previous_state @state = state @configuration = configuration @mode = mode end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
3 4 5 |
# File 'lib/end_state/transition.rb', line 3 def configuration @configuration end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
3 4 5 |
# File 'lib/end_state/transition.rb', line 3 def mode @mode end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
3 4 5 |
# File 'lib/end_state/transition.rb', line 3 def object @object end |
#previous_state ⇒ Object (readonly)
Returns the value of attribute previous_state.
3 4 5 |
# File 'lib/end_state/transition.rb', line 3 def previous_state @previous_state 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?(params = {}) ⇒ Boolean
20 21 22 23 |
# File 'lib/end_state/transition.rb', line 20 def allowed?(params={}) return params_not_provided(missing_params(params)) unless missing_params(params).empty? guards.all? { |guard| guard.new(object, state, params).allowed? } end |
#call(params = {}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/end_state/transition.rb', line 13 def call(params={}) return guard_failed unless allowed?(params) return false unless action.new(object, state).call return conclude_failed unless conclude(params) true end |
#will_allow?(params = {}) ⇒ Boolean
25 26 27 28 |
# File 'lib/end_state/transition.rb', line 25 def will_allow?(params={}) return false unless missing_params(params).empty? guards.all? { |guard| guard.new(object, state, params).will_allow? } end |