Class: Enum::Transitions::UpdateHandler
- Inherits:
-
Object
- Object
- Enum::Transitions::UpdateHandler
- Includes:
- Naming
- Defined in:
- lib/enum/transitions/update_handler.rb
Instance Method Summary collapse
- #around_update(model) ⇒ Object
-
#initialize(config) ⇒ UpdateHandler
constructor
A new instance of UpdateHandler.
Methods included from Naming
#entering_event, #leaving_event, #transition_event
Constructor Details
#initialize(config) ⇒ UpdateHandler
Returns a new instance of UpdateHandler.
7 8 9 |
# File 'lib/enum/transitions/update_handler.rb', line 7 def initialize(config) @config = config end |
Instance Method Details
#around_update(model) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/enum/transitions/update_handler.rb', line 11 def around_update(model) source, target = model.changes[@config.enum] transition = @config.transitions.dig(source, target) raise Errors::TransitionNotAllowed if transition.nil? model.run_callbacks transition do model.run_callbacks leaving_event(source) do model.run_callbacks entering_event(target) do yield end end end end |