Sha256: 53e4796a6d110a6d3831b59e6b1a4a572006d6d8a27abf860e7cd1189ae422df

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 KB

Contents

module Rake
  module Funnel
    module Integration
      module TeamCity
        class ServiceMessages
          class << self
            def respond_to_missing?(_method, _include_private = false)
              true
            end

            def method_missing(method, *args, &_block) # rubocop:disable Style/MethodMissing
              return unless Rake::Funnel::Integration::TeamCity.running?

              message_name = method.camelize
              publish(message_name, args[0])
            end

            private

            def publish(message_name, args)
              args = [message_name] << escaped_array_of(args)
              args = args.flatten.reject(&:nil?)

              puts "##teamcity[#{args.join(' ')}]"
            end

            def escape(string) # rubocop:disable Metrics/MethodLength
              string
                .to_s
                .gsub(/\|/, '||')
                .gsub(/'/, "|'")
                .gsub(/\r/, '|r')
                .gsub(/\n/, '|n')
                .gsub(/\u0085/, '|x')
                .gsub(/\u2028/, '|l')
                .gsub(/\u2029/, '|p')
                .gsub(/\[/, '|[')
                .gsub(/\]/, '|]')
            end

            def escaped_array_of(args)
              return [] if args.nil?

              return "'#{escape(args)}'" unless args.is_a?(Hash)
              args.map { |key, value| "#{key.camelize}='#{escape(value.to_s)}'" }
            end
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rake-funnel-0.22.1 lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.22.0 lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.21.2 lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.21.1 lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.21.0 lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.20.2 lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.20.1 lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.20.0 lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.19.0 lib/rake/funnel/integration/teamcity/service_messages.rb