File: destination_base.rb

package info (click to toggle)
ruby-process-executer 4.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 408 kB
  • sloc: ruby: 873; makefile: 4
file content (73 lines) | stat: -rw-r--r-- 2,211 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# frozen_string_literal: true

module ProcessExecuter
  module Destinations
    # Base class for all destination handlers
    #
    # Provides the common interface and functionality for all destination
    # classes that handle different types of output redirection.
    #
    # @api private
    class DestinationBase
      # Initializes a new destination handler
      #
      # @param destination [Object] the destination to write to
      #
      def initialize(destination)
        @destination = destination
      end

      # The destination object this handler manages
      #
      # @return [Object] the destination object
      attr_reader :destination

      # Writes data to the destination
      #
      # Subclasses should override this method to provide specific write behavior.
      # The base implementation is a no-op.
      #
      # @param _data [String] the data to write
      #
      # @return [Integer] the number of bytes written
      #
      def write(_data)
        0
      end

      # Closes the destination if necessary
      #
      # By default, this method does nothing. Subclasses should override
      # this method if they need to perform cleanup.
      #
      # @return [void]
      def close; end

      # Determines if this class can handle the given destination
      #
      # This is an abstract class method that must be implemented by subclasses.
      #
      # @param destination [Object] the destination to check
      # @return [Boolean] true if this class can handle the destination
      # @raise [NotImplementedError] if the subclass doesn't implement this method
      def self.handles?(destination)
        raise NotImplementedError
      end

      # Determines if this destination class can be wrapped by MonitoredPipe
      #
      # All destination types can be wrapped by MonitoredPipe unless they explicitly
      # opt out.
      #
      # @return [Boolean]
      def self.compatible_with_monitored_pipe? = true

      # Determines if this destination instance can be wrapped by MonitoredPipe
      #
      # @return [Boolean]
      def compatible_with_monitored_pipe?
        self.class.compatible_with_monitored_pipe?
      end
    end
  end
end