Class: Kuby::PluginRegistry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/kuby/plugin_registry.rb

Constant Summary collapse

ANY =
'any'.freeze

Instance Method Summary collapse

Instance Method Details

#each(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kuby/plugin_registry.rb', line 24

def each(&block)
  return to_enum(__method__) unless block

  @plugins.each_pair do |plugin_name, plugins_by_env|
    plugins_by_env.each_pair do |env, plugin_klass|
      case env
        when ANY, Kuby.env
          yield plugin_name, plugin_klass
      end
    end
  end
end

#find(plugin_name, environment: Kuby.env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/kuby/plugin_registry.rb', line 13

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

#register(plugin_name, plugin_klass, environment: ANY) ⇒ Object



8
9
10
11
# File 'lib/kuby/plugin_registry.rb', line 8

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