diff options
Diffstat (limited to 'lib/blink/statechange.rb')
-rw-r--r-- | lib/blink/statechange.rb | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/blink/statechange.rb b/lib/blink/statechange.rb index 0f2987fb9..e50f67c5a 100644 --- a/lib/blink/statechange.rb +++ b/lib/blink/statechange.rb @@ -8,7 +8,7 @@ module Blink class StateChange - attr_accessor :is, :should, :type, :path, :state + attr_accessor :is, :should, :type, :path, :state, :transaction #--------------------------------------------------------------- def initialize(state) @@ -23,15 +23,47 @@ module Blink #--------------------------------------------------------------- def forward Blink.notice "moving change forward" + + unless defined? @transaction + raise "StateChange '%s' tried to be executed outside of transaction" % + self + end if @state.noop Blink.notice "%s is noop" % @state Blink.notice "change noop is %s" % @state.noop else Blink.notice "Calling sync on %s" % @state begin - @state.sync + event = @state.sync + + # default to a simple event type + if event.nil? + event = @state.parent.name.id2name + "_changed" + elsif ! event.is_a?(Symbol) + Blink.notice "State '%s' retuned invalid event '%s'; resetting to default" % + [@state.class,event] + + event = @state.parent.name.id2name + "_changed" + end + + # i should maybe include object type, but the event type + # should basically point to that, right? + return Blink::Event.new( + :event => event, + :object => @state.parent, + :transaction => @transaction, + :message => self.to_s + ) rescue => detail Blink.error "%s failed: %s" % [self.to_s,detail] + # there should be a way to ask the state what type of event + # it would have generated, but... + return Blink::Event.new( + :event => @state.parent.name.id2name + "_failed", + :object => @state.parent, + :transaction => @transaction, + :message => "Failed: " + self.to_s + ) end end end |