Sha256: 7f96021f066bbebd9416b4430c26e9042d48417b5d57d53ba281cb22e9d636a2

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Buildkite
  module Builder
    class ExtensionManager
      include LoggingUtils
      using Rainbow

      def initialize(context)
        @context = context
        @extensions = []

        Loaders::Extensions.load(@context.root)
      end

      def use(extension, **args)
        unless extension < Buildkite::Builder::Extension
          raise "#{extension} must subclass Buildkite::Builder::Extension"
        end

        @extensions.push(extension.new(@context, **args))
        @context.dsl.extend(extension)
      end

      def build
        @extensions.each do |extension|
          log_build(extension.class.name) { extension.build }
        end
      end

      private

      def log
        @context.logger
      end

      def log_build(name)
        log.info "\nProcessing ".color(:dimgray) + name.color(:springgreen)

        results = benchmark('└──'.color(:springgreen) + ' Finished in %s'.color(:dimgray)) do
          formatter = log.formatter
          log.formatter = proc do |_severity, _datetime, _progname, msg|
            '│'.color(:springgreen) + " #{msg}\n"
          end

          begin
            yield
          ensure
            log.formatter = formatter
          end
        end

        log.info results
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
buildkite-builder-2.0.0.beta1 lib/buildkite/builder/extension_manager.rb