Sha256: d265a7824d74f2fd0b4e8408c2bd0141a52dcbaafe18ff5692df70f4968c7a84

Contents?: true

Size: 655 Bytes

Versions: 16

Compression:

Stored size: 655 Bytes

Contents

# typed: false
module Kuby
  class PluginRegistry
    ANY = 'any'.freeze

    def register(plugin_name, plugin_klass, environment: ANY)
      plugins[plugin_name] ||= {}
      plugins[plugin_name][environment] ||= plugin_klass
    end

    def find(plugin_name, environment: Kuby.env)
      plugins_by_env = plugins[plugin_name]

      unless plugins_by_env
        raise Kubernetes::MissingPluginError, "no plugin registered with name #{plugin_name}, "\
          'do you need to add a gem to your Gemfile?'
      end

      plugins_by_env[environment] || plugins_by_env[ANY]
    end

    private

    def plugins
      @plugins ||= {}
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
kuby-core-0.16.1 lib/kuby/plugin_registry.rb
kuby-core-0.16.0 lib/kuby/plugin_registry.rb
kuby-core-0.15.0 lib/kuby/plugin_registry.rb
kuby-core-0.14.0 lib/kuby/plugin_registry.rb
kuby-core-0.13.0 lib/kuby/plugin_registry.rb
kuby-core-0.12.0 lib/kuby/plugin_registry.rb
kuby-core-0.11.16 lib/kuby/plugin_registry.rb
kuby-core-0.11.15 lib/kuby/plugin_registry.rb
kuby-core-0.11.14 lib/kuby/plugin_registry.rb
kuby-core-0.11.13 lib/kuby/plugin_registry.rb
kuby-core-0.11.12 lib/kuby/plugin_registry.rb
kuby-core-0.11.11 lib/kuby/plugin_registry.rb
kuby-core-0.11.10 lib/kuby/plugin_registry.rb
kuby-core-0.11.9 lib/kuby/plugin_registry.rb
kuby-core-0.11.8 lib/kuby/plugin_registry.rb
kuby-core-0.11.7 lib/kuby/plugin_registry.rb