summaryrefslogtreecommitdiff
path: root/lib/chef/event_dispatch/events_output_stream.rb
blob: d9c21642b7530c358defb1236c326428469761e6 (plain)
1
2
3
4
5
6
7
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
35
36
37
class Chef
  module EventDispatch
    class EventsOutputStream
      # This is a fake stream that connects to events.
      #
      # == Arguments
      # events: the EventDispatch object to send data to (run_context.events)
      # options is a hash with these possible options:
      # - name: a string that identifies the stream to the user. Preferably short.

      def initialize(events, options = {})
        @events = events
        @options = options
        events.stream_opened(self, options)
      end

      attr_reader :options
      attr_reader :events

      def print(str)
        events.stream_output(self, str, options)
      end

      def <<(str)
        events.stream_output(self, str, options)
      end

      def write(str)
        events.stream_output(self, str, options)
      end

      def close
        events.stream_closed(self, options)
      end
    end
  end
end