Sha256: 0f7375f490299b969593fe4bafee12e04799cbeaa363ff288c1b02cb1b76197c

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Buildkite
  module Builder
    class PluginCollection
      attr_reader :plugin_manager

      def initialize(plugin_manager)
        @plugin_manager = plugin_manager
        @collection = []
      end

      def add(resource, options = nil)
        plugin =
          case resource
          when Symbol
            uri = plugin_manager.fetch(resource.to_s)

            raise ArgumentError, "Plugin `#{resource}` does not exist" unless uri

            Plugin.new(uri, options)
          when String
            Plugin.new(resource, options)
          when Plugin
            resource
          else
            raise ArgumentError, "Unknown plugin `#{resource.inspect}`"
          end

        @collection.push(plugin).last
      end

      def find(source)
        source_string =
          case source
          when String then source
          when Plugin then source.source
          else raise ArgumentError, "Unknown source #{source.inpect}"
          end

        @collection.select do |plugin|
          plugin.source == source_string
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
buildkite-builder-2.0.0.beta3 lib/buildkite/builder/plugin_collection.rb