Class: ShortBus::Monitor
- Inherits:
-
Object
- Object
- ShortBus::Monitor
- Defined in:
- lib/short_bus/monitor.rb
Overview
For printing out all messages
Instance Method Summary collapse
-
#initialize(*args) ⇒ Monitor
constructor
A new instance of Monitor.
- #monitor(message) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(*args) ⇒ Monitor
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/short_bus/monitor.rb', line 8 def initialize(*args) = { message_spec: nil, name: 'ShortBus::Monitor', service: method(:monitor), suppress_payload: false, suppress_publisher: false, publisher_spec: nil, thread_count: 1 } @suppress_payload, @suppress_publisher = nil if args[0].is_a?(Hash) && args[0].key?(:driver) .merge! args[0] @driver = [:driver] .delete(:driver) elsif args.is_a?(Array) && args.length == 1 @driver = args[0] else raise ArgumentError, 'No driver passed.' end @suppress_payload = .delete(:suppress_payload) @suppress_publisher = .delete(:suppress_publisher) start end |
Instance Method Details
#monitor(message) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/short_bus/monitor.rb', line 36 def monitor() puts "[#{@options[:name]}] message = #{message}" printf( " %s payload = %s\n", [:name] ? ' ' * [:name].length : '', .payload.inspect ) if .payload && !@suppress_payload printf( " %spublisher = %s\n", [:name] ? ' ' * [:name].length : '', .publisher ? .publisher : '*ANONYMOUS*' ) unless @suppress_publisher nil end |
#start ⇒ Object
51 52 53 |
# File 'lib/short_bus/monitor.rb', line 51 def start @service = @driver.subscribe() end |
#stop ⇒ Object
55 56 57 |
# File 'lib/short_bus/monitor.rb', line 55 def stop @driver.unsubscribe @service end |