lib/ruote/log/test_logger.rb in ruote-2.1.11 vs lib/ruote/log/test_logger.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
@@ -34,11 +34,11 @@
attr_reader :seen
attr_reader :log
attr_accessor :noisy
- def initialize (context)
+ def initialize(context)
@context = context
if @context.worker
#
@@ -59,11 +59,11 @@
@count = -1
@color = 33
@noisy = false
end
- def notify (msg)
+ def notify(msg)
puts(pretty_print(msg)) if @noisy
@seen << msg
@log << msg
@@ -82,11 +82,11 @@
# wait_for may only be used by one thread at a time. If one
# thread calls wait_for and later another thread calls wait_for
# while the first thread is waiting, the first thread's
# interests are lost and the first thread will never wake up.
#
- def wait_for (interests)
+ def wait_for(interests)
@waiting << [ Thread.current, interests ]
check_waiting
@@ -102,16 +102,16 @@
def dump
@seen.collect { |msg| pretty_print(msg) }.join("\n")
end
- def color= (c)
+ def color=(c)
@color = c
end
- def self.pp (msg)
+ def self.pp(msg)
@logger ||= TestLogger.new(nil)
puts @logger.send(:pretty_print, msg)
end
@@ -124,11 +124,11 @@
while msg = @seen.shift
check_msg(msg)
end
end
- def check_msg (msg)
+ def check_msg(msg)
wakeup = []
@waiting.each do |thread, interests|
@@ -156,41 +156,43 @@
# the last workflow being run finishes).
#
# Returns true if all interests being waited for have been satisfied,
# false otherwise.
#
- def matches (interests, msg)
+ def matches(interests, msg)
action = msg['action']
interests.each do |interest|
- satisfied = if interest == :inactive
+ satisfied = case interest
- (FINAL_ACTIONS.include?(action) && @context.worker.inactive?)
+ when :inactive
- elsif interest == :empty
+ (FINAL_ACTIONS.include?(action) && @context.worker.inactive?)
- (action == 'terminated' && @context.storage.empty?('expressions'))
+ when :empty
- elsif interest.is_a?(Symbol) # participant
+ (action == 'terminated' && @context.storage.empty?('expressions'))
- (action == 'dispatch' && msg['participant_name'] == interest.to_s)
+ when Symbol
- elsif interest.is_a?(Fixnum)
+ (action == 'dispatch' && msg['participant_name'] == interest.to_s)
- interests.delete(interest)
+ when Fixnum
- if (interest > 1)
- interests << (interest - 1)
- false
- else
- true
- end
+ interests.delete(interest)
- else # wfid
+ if (interest > 1)
+ interests << (interest - 1)
+ false
+ else
+ true
+ end
- (FINAL_ACTIONS.include?(action) && msg['wfid'] == interest)
+ else # wfid
+
+ (FINAL_ACTIONS.include?(action) && msg['wfid'] == interest)
end
interests.delete(interest) if satisfied
end