lib/ruote/part/block_participant.rb in ruote-2.1.11 vs lib/ruote/part/block_participant.rb in ruote-2.2.0
- old
+ new
@@ -1,7 +1,7 @@
#--
-# Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
+# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -65,38 +65,49 @@
class BlockParticipant
include LocalParticipant
attr_accessor :context
- attr_accessor :do_not_thread
- def initialize (block, opts)
+ def initialize(opts)
@opts = opts
- @block = block
- @do_not_thread = false
end
- def consume (workitem)
+ def do_not_thread
- r = if @block.arity == 1
+ @opts['do_not_thread']
+ end
- @block.call(workitem)
+ def consume(workitem)
+
+ block = @opts['block']
+
+ @context.treechecker.block_check(block)
+ # raises in case of 'security' violation
+
+ #block = eval(block, @context.send(:binding))
+ # doesn't work with ruby 1.9.2-p136
+ block = eval(block, @context.instance_eval { binding })
+ # works OK with ruby 1.8.7-249 and 1.9.2-p136
+
+ r = if block.arity == 1
+
+ block.call(workitem)
else
- @block.call(
+ block.call(
workitem, Ruote::Exp::FlowExpression.fetch(@context, workitem.h.fei))
end
if r != nil && r != workitem
- #workitem.result = r
workitem.result = (Rufus::Json.dup(r) rescue nil)
end
reply_to_engine(workitem)
end
- def cancel (fei, flavour)
+ def cancel(fei, flavour)
# do nothing
end
end
end