This file is indexed.

/usr/lib/ruby/vendor_ruby/aruba/platforms/announcer.rb is in ruby-aruba 0.14.2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
require 'shellwords'
require 'aruba/colorizer'

Aruba::AnsiColor.coloring = false if !STDOUT.tty? && !ENV.key?("AUTOTEST")

# Aruba
module Aruba
  # Platforms
  module Platforms
    # Announcer
    #
    # @private
    #
    # @example Activate your you own channel in cucumber
    #
    #   Before('@announce-my-channel') do
    #     aruba.announcer.activate :my_channel
    #   end
    #
    # @example Activate your you own channel in rspec > 3
    #
    #   before do
    #     current_example = context.example
    #     aruba.announcer.activate :my_channel if current_example.metadata[:announce_my_channel]
    #   end
    #
    #   Aruba.announcer.announce(:my_channel, 'my message')
    #
    class Announcer
      # Announcer using Kernel.puts
      class KernelPutsAnnouncer
        def announce(message)
          Kernel.puts message
        end

        def mode?(m)
          :kernel_puts == m
        end
      end

      # Announcer using Main#puts
      class PutsAnnouncer
        def announce(message)
          puts message
        end

        def mode?(m)
          :puts == m
        end
      end

      private

      attr_reader :announcers, :announcer, :channels, :output_formats, :colorizer

      public

      def initialize(*args)
        @announcers = []
        @announcers << PutsAnnouncer.new
        @announcers << KernelPutsAnnouncer.new

        @colorizer = Aruba::Colorizer.new

        @announcer         = @announcers.first
        @channels          = {}
        @output_formats    = {}

        @options           = args[1] || {}

        after_init
      end

      private

      # rubocop:disable Metrics/MethodLength
      def after_init
        output_format :changed_configuration, proc { |n, v| format('# %s = %s', n, v) }
        output_format :changed_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
        output_format :command, '$ %s'
        output_format :directory, '$ cd %s'
        output_format :environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
        output_format :full_environment, proc { |h| format("<<-ENVIRONMENT\n%s\nENVIRONMENT", Aruba.platform.simple_table(h)) }
        output_format :modified_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
        output_format :stderr, "<<-STDERR\n%s\nSTDERR"
        output_format :stdout, "<<-STDOUT\n%s\nSTDOUT"
        output_format :command_content, "<<-COMMAND\n%s\nCOMMAND"
        output_format :stop_signal, proc { |p, s| format('Command will be stopped with `kill -%s %s`', s, p) }
        output_format :timeout, '# %s-timeout: %s seconds'
        output_format :wait_time, '# %s: %s seconds'
        # rubocop:disable Metrics/LineLength
        output_format :command_filesystem_status, proc { |status| format("<<-COMMAND FILESYSTEM STATUS\n%s\nCOMMAND FILESYSTEM STATUS", Aruba.platform.simple_table(status.to_h, :sort => false)) }
        # rubocop:enable Metrics/LineLength

        # rubocop:disable Metrics/LineLength
        if @options[:stdout]
          warn('The use of "@announce_stdout-instance" variable and "options[:stdout] = true" for Announcer.new is deprecated. Please use "announcer.activate(:stdout)" instead.')
          activate :stdout
        end
        if @options[:stderr]
          warn('The use of "@announce_stderr-instance" variable and "options[:stderr] = true" for Announcer.new is deprecated. Please use "announcer.activate(:stderr)" instead.')
          activate :stderr
        end
        if @options[:dir]
          warn('The use of "@announce_dir-instance" variable and "options[:dir] = true" for Announcer.new is deprecated. Please use "announcer.activate(:directory)" instead.')
          activate :directory
        end
        if @options[:cmd]
          warn('The use of "@announce_cmd-instance" variable and "options[:cmd] = true" for Announcer.new is deprecated. Please use "announcer.activate(:command)" instead.')
          activate :command
        end
        if @options[:env]
          warn('The use of "@announce_env-instance" variable and "options[:env] = true" for Announcer.new is deprecated. Please use "announcer.activate(:modified_environment)" instead.')
          activate :modified_enviroment
        end
        # rubocop:enable Metrics/LineLength
      end
      # rubocop:enable Metrics/MethodLength

      def output_format(channel, string = '%s', &block)
        output_formats[channel.to_sym] = if block_given?
                                           block
                                         elsif string.is_a?(Proc)
                                           string
                                         else
                                           proc { |*args| format(string, *args) }
                                         end
      end

      public

      # Reset announcer
      def reset
        @announcer = @announcers.first
      end

      # Change mode of announcer
      #
      # @param [Symbol] m
      #   The mode to set
      def mode=(m)
        @announcer = @announcers.find { |a| f.mode? m.to_sym }

        self
      end

      # Check if channel is activated
      #
      # @param [Symbol] channel
      #   The name of the channel to check
      def activated?(channel)
        channels[channel.to_sym] == true
      end

      # Activate a channel
      #
      # @param [Symbol] channel
      #   The name of the channel to activate
      def activate(*chns)
        chns.flatten.each { |c| channels[c.to_sym] = true }

        self
      end

      # Announce information to channel
      #
      # @param [Symbol] channel
      #   The name of the channel to check
      #
      # @param [Array] args
      #   Arguments
      #
      # @yield
      #   If block is given, that one is called and the return value is used as
      #   message to be announced.
      def announce(channel, *args, &block)
        channel = channel.to_sym

        the_output_format = if output_formats.key? channel
                              output_formats[channel]
                            else
                              proc { |v| format('%s', v) }
                            end

        return unless activated?(channel)

        message = if block_given?
                    the_output_format.call(yield)
                  else
                    the_output_format.call(*args)
                  end
        message += "\n"
        message = colorizer.cyan(message)

        announcer.announce(message)

        nil
      end

      # @deprecated
      def stdout(content)
        warn('The announcer now has a new api to activate channels. Please use this one: announce(:stdout, message)')
        announce :stdout, content
      end

      # @deprecated
      def stderr(content)
        warn('The announcer now has a new api to activate channels. Please use this one: announce(:stderr, message)')
        announce :stderr, content
      end

      # @deprecated
      def dir(dir)
        warn('The announcer now has a new api to activate channels. Please use this one announce(:directory, message)')
        announce :directory, dir
      end

      # @deprecated
      def cmd(cmd)
        warn('The announcer now has a new api to activate channels. Please use this one announce(:command, message)')
        announce :command, cmd
      end

      # @deprecated
      def env(name, value)
        warn('The announcer now has a new api to activate channels. Please use this one: announce(:changed_environment, key, value)')

        announce :changed_environment, name, value
      end
    end
  end
end