summaryrefslogtreecommitdiffstats
path: root/lib/blink/statechange.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/blink/statechange.rb')
-rw-r--r--lib/blink/statechange.rb95
1 files changed, 55 insertions, 40 deletions
diff --git a/lib/blink/statechange.rb b/lib/blink/statechange.rb
index e50f67c5a..e5d27cc58 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, :transaction
+ attr_accessor :is, :should, :type, :path, :state, :transaction, :run
#---------------------------------------------------------------
def initialize(state)
@@ -17,6 +17,51 @@ module Blink
@path = state.fqpath
@is = state.is
@should = state.should
+
+ @run = false
+ end
+ #---------------------------------------------------------------
+
+ #---------------------------------------------------------------
+ def go
+ if @state.noop
+ Blink.notice "%s is noop" % @state
+ return nil
+ end
+
+ begin
+ event = @state.sync
+ @run = true
+
+ # default to a simple event type
+ if event.nil?
+ event = @state.parent.name.id2name + "_changed"
+ elsif ! event.is_a?(Symbol)
+ Blink.notice "State '%s' returned 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
#---------------------------------------------------------------
@@ -28,50 +73,20 @@ module Blink
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
- 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
+
+ return self.go
end
#---------------------------------------------------------------
#---------------------------------------------------------------
def backward
- raise "Moving statechanges backward is currently unsupported"
+ @state.should = @is
+ @state.retrieve
+
+ Blink.notice "Rolling %s backward" % self
+ return self.go
+
+ #raise "Moving statechanges backward is currently unsupported"
#@type.change(@path,@should,@is)
end
#---------------------------------------------------------------