Sha256: 88ec319dbdcb7e944df9cf804614ce475369963e0b2ec42f81ea3b1fc55034ec

Contents?: true

Size: 1.53 KB

Versions: 23

Compression:

Stored size: 1.53 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, native: false, **args, &block)
        unless extension < Buildkite::Builder::Extension
          raise "#{extension.name} must subclass Buildkite::Builder::Extension"
        end

        if @extensions[extension]
          raise "#{extension.name} already registered"
        end

        @extensions[extension] = extension.new(@context, **args, &block)
        @context.dsl.extend(extension)
      end

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

      def find(klass)
        @extensions.fetch(klass)
      end

      def all
        @extensions.keys
      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

23 entries across 23 versions & 1 rubygems

Version Path
buildkite-builder-4.15.1 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.15.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.14.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.13.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.12.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.11.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.10.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.8.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.7.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.6.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.5.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.4.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.3.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.2.5 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.2.4 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.2.3 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.2.2 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.2.1 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.2.0 lib/buildkite/builder/extension_manager.rb
buildkite-builder-4.1.2 lib/buildkite/builder/extension_manager.rb