Sha256: b29f3935d30e3cb5656c8a36172c288d099195483a039a221805a668cecc8003

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

module Rake::Funnel::Integration::TeamCity
  class ServiceMessages
    class << self
      def method_missing(method, *args, &block)
        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)
        string
          .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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rake-funnel-0.3.2.pre lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.3.1.pre lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.3.0.pre lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.2.0.pre lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.1.0.pre lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.0.6.pre lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.0.5.pre lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.0.4.pre lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.0.3.pre lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.0.2.pre lib/rake/funnel/integration/teamcity/service_messages.rb
rake-funnel-0.0.1.pre lib/rake/funnel/integration/teamcity/service_messages.rb