Sha256: 45fb1479c825ccae3ca2db008ae77c8804ecdfce17d3f9b783d5b18217e71066

Contents?: true

Size: 724 Bytes

Versions: 2

Compression:

Stored size: 724 Bytes

Contents

require 'json'

module Hallmonitor
  module Outputters
    # Simple outputter that just prints to an output stream
    class IOOutputter < Outputter

      # Builds a new IOOutputter
      # @param name [String] Name for this outputter
      # @param out [IO] Output to write to
      def initialize(name, out)
        super(name)
        @out = out
      end

      # Sends an event to the configured output
      # on IOError the output will be closed
      def process(event)
        begin
          @out.print "EVENT: #{event.to_json}\n"
          @out.flush
        rescue IOError => e
          close
        end
      end

      private
      def close
        @out.close unless @out.nil?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hallmonitor-1.1.0 lib/hallmonitor/outputters/iooutputter.rb
hallmonitor-1.0.0 lib/hallmonitor/outputters/iooutputter.rb