Class: KuberKit::ServiceDeployer::Deployer

Inherits:
Object
  • Object
show all
Defined in:
lib/kuber_kit/service_deployer/deployer.rb

Constant Summary collapse

StrategyNotFoundError =
Class.new(KuberKit::NotFoundError)

Instance Method Summary collapse

Constructor Details

#initialize(**injected_deps) ⇒ Deployer



11
12
13
14
# File 'lib/kuber_kit/service_deployer/deployer.rb', line 11

def initialize(**injected_deps)
  super(injected_deps)
  add_default_strategies
end

Instance Method Details

#deploy(shell, service, strategy_name) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/kuber_kit/service_deployer/deployer.rb', line 27

def deploy(shell, service, strategy_name)
  deployer = @@strategies[strategy_name]

  raise StrategyNotFoundError, "Can't find strategy with name #{strategy_name}" if deployer.nil?

  deployer.deploy(shell, service)
end

#register_strategy(strategy_name, strategy) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/kuber_kit/service_deployer/deployer.rb', line 16

def register_strategy(strategy_name, strategy)
  @@strategies ||= {}

  if !strategy.is_a?(KuberKit::ServiceDeployer::Strategies::Abstract)
    raise ArgumentError.new("should be an instance of KuberKit::ServiceDeployer::Strategies::Abstract, got: #{strategy.inspect}")
  end

  @@strategies[strategy_name] = strategy
end

#reset!Object



35
36
37
# File 'lib/kuber_kit/service_deployer/deployer.rb', line 35

def reset!
  @@strategies = {}
end