lib/end_state/transition.rb in end_state-0.4.0 vs lib/end_state/transition.rb in end_state-0.9.0
- old
+ new
@@ -1,29 +1,29 @@
module EndState
class Transition
attr_reader :state, :blocked_event_message
- attr_accessor :action, :guards, :finalizers
+ attr_accessor :action, :guards, :concluders
def initialize(state)
@state = state
@action = Action
@guards = []
- @finalizers = []
+ @concluders = []
end
def allowed?(object, params={})
guards.all? { |guard| guard.new(object, state, params).allowed? }
end
def will_allow?(object, params={})
guards.all? { |guard| guard.new(object, state, params).will_allow? }
end
- 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)
+ def conclude(object, previous_state, params={})
+ concluders.each_with_object([]) do |concluder, concluded|
+ concluded << concluder
+ return rollback(concluded, object, previous_state, params) unless run_concluder(concluder, object, state, params)
end
true
end
def custom_action(action)
@@ -32,30 +32,36 @@
def guard(guard)
guards << guard
end
- def finalizer(finalizer)
- finalizers << finalizer
+ def concluder(concluder)
+ concluders << concluder
end
def persistence_on
- finalizer Finalizers::Persistence
+ concluder Concluders::Persistence
end
def blocked(message)
@blocked_event_message = message
end
+ # Backward compatibility
+ # Finalizer is deprecated
+ alias_method :finalizers, :concluders
+ alias_method :finalize, :conclude
+ alias_method :finalizer, :concluder
+
private
- def rollback(finalized, object, previous_state, params)
+ def rollback(concluded, object, previous_state, params)
action.new(object, previous_state).rollback
- finalized.reverse.each { |finalizer| finalizer.new(object, state, params).rollback }
+ concluded.reverse.each { |concluder| concluder.new(object, state, params).rollback }
false
end
- def run_finalizer(finalizer, object, state, params)
- finalizer.new(object, state, params).call
+ def run_concluder(concluder, object, state, params)
+ concluder.new(object, state, params).call
end
end
end