Sha256: 9e5db05f381c2361b481929e2f6b6d3afa905482f40e494cc0c53d0276a17caa

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 KB

Contents

class KuberKit::Core::ServiceDefinition
  attr_reader :service_name, :template_name, :dependencies, :initializers
  
  Contract Or[Symbol, String] => Any
  def initialize(service_name)
    @service_name = service_name.to_sym
    @initializers = []
  end

  def to_service_attrs
    OpenStruct.new(
      name:               @service_name,
      initializers:       @initializers,
      template_name:      get_value(@template_name),
      tags:               Array(get_value(@tags)).map(&:to_sym),
      images:             Array(get_value(@images)).map(&:to_sym),
      attributes:         get_value(@attributes),
      deployer_strategy:  get_value(@deployer_strategy),
      generator_strategy: get_value(@generator_strategy),
    )
  end

  def depends_on(*value, &block)
    initialize_with(value)
    self
  end

  def initialize_with(*value, &block)
    @initializers = Array(value).flatten
    self
  end

  def template(value = nil, &block)
    @template_name = block_given? ? block : value

    self
  end

  def tags(*value, &block)
    @tags = block_given? ? block : Array(value).flatten

    self
  end

  def images(*value, &block)
    @images = block_given? ? block : Array(value).flatten

    self
  end

  def attributes(value = nil, &block)
    @attributes = block_given? ? block : value

    self
  end

  def deployer_strategy(value = nil, &block)
    @deployer_strategy = block_given? ? block : value

    self
  end

  def generator_strategy(value = nil, &block)
    @generator_strategy = block_given? ? block : value

    self
  end

  private
    def get_value(variable)
      variable.is_a?(Proc) ? variable.call : variable
    end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
kuber_kit-1.3.8 lib/kuber_kit/core/service_definition.rb
kuber_kit-1.3.7 lib/kuber_kit/core/service_definition.rb
kuber_kit-1.1.8 lib/kuber_kit/core/service_definition.rb
kuber_kit-1.3.6 lib/kuber_kit/core/service_definition.rb
kuber_kit-1.1.7 lib/kuber_kit/core/service_definition.rb
kuber_kit-1.3.5 lib/kuber_kit/core/service_definition.rb
kuber_kit-1.3.4 lib/kuber_kit/core/service_definition.rb
kuber_kit-1.1.6 lib/kuber_kit/core/service_definition.rb
kuber_kit-1.3.3 lib/kuber_kit/core/service_definition.rb
kuber_kit-1.3.2 lib/kuber_kit/core/service_definition.rb