Class: Ruote::TestLogger
- Inherits:
-
Object
- Object
- Ruote::TestLogger
- Includes:
- PrettyLogging
- Defined in:
- lib/ruote/log/test_logger.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#noisy ⇒ Object
Returns the value of attribute noisy.
-
#seen ⇒ Object
readonly
Returns the value of attribute seen.
Class Method Summary collapse
Instance Method Summary collapse
- #color=(c) ⇒ Object
-
#dump ⇒ Object
Debug only : dumps all the seen events to STDOUTS.
-
#initialize(context) ⇒ TestLogger
constructor
A new instance of TestLogger.
- #notify(msg) ⇒ Object
-
#wait_for(interests) ⇒ Object
Blocks until one or more interests are satisfied.
Constructor Details
#initialize(context) ⇒ TestLogger
Returns a new instance of TestLogger.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruote/log/test_logger.rb', line 39 def initialize(context) @context = context if @context.worker # # this is a worker context, DO log # @context.worker.subscribe(:all, self) #else # # this is not a worker context, DO NOT log, but be ready to # be queried # end @seen = [] @log = [] @waiting = [] @count = -1 @color = 33 @noisy = false end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
35 36 37 |
# File 'lib/ruote/log/test_logger.rb', line 35 def log @log end |
#noisy ⇒ Object
Returns the value of attribute noisy.
37 38 39 |
# File 'lib/ruote/log/test_logger.rb', line 37 def noisy @noisy end |
#seen ⇒ Object (readonly)
Returns the value of attribute seen.
34 35 36 |
# File 'lib/ruote/log/test_logger.rb', line 34 def seen @seen end |
Class Method Details
.pp(msg) ⇒ Object
118 119 120 121 122 |
# File 'lib/ruote/log/test_logger.rb', line 118 def self.pp(msg) @logger ||= TestLogger.new(nil) puts @logger.send(:pretty_print, msg) end |
Instance Method Details
#color=(c) ⇒ Object
113 114 115 116 |
# File 'lib/ruote/log/test_logger.rb', line 113 def color=(c) @color = c end |
#dump ⇒ Object
Debug only : dumps all the seen events to STDOUTS
108 109 110 111 |
# File 'lib/ruote/log/test_logger.rb', line 108 def dump @seen.collect { |msg| pretty_print(msg) }.join("\n") end |
#notify(msg) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ruote/log/test_logger.rb', line 64 def notify(msg) puts(pretty_print(msg)) if @noisy if msg['action'] != 'noop' @seen << msg @log << msg end check_waiting end |
#wait_for(interests) ⇒ Object
Blocks until one or more interests are satisfied.
interests must be an array of interests. Please refer to Engine#wait_for documentation for allowed values of each interest.
If multiple interests are given, wait_for blocks until all of the interests are satisfied.
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.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ruote/log/test_logger.rb', line 89 def wait_for(interests) @waiting << [ Thread.current, interests ] #check_waiting @context.storage.put_msg('noop', {}) # # forces the #check_waiting via #notify # (ie let it happen in the worker) Thread.stop if @waiting.find { |w| w.first == Thread.current } # and when this thread gets woken up, go on and return __result__ Thread.current['__result__'] end |