Sha256: 26fb0f897a41d16584274f7b001e391c4edf013475b1fc10b08b98040b472da3

Contents?: true

Size: 1 KB

Versions: 9

Compression:

Stored size: 1 KB

Contents

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

  def to_service_attrs
    OpenStruct.new(
      name:           @service_name,
      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),
    )
  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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kuber_kit-0.2.3 lib/kuber_kit/core/service_definition.rb
kuber_kit-0.2.2 lib/kuber_kit/core/service_definition.rb
kuber_kit-0.2.1 lib/kuber_kit/core/service_definition.rb
kuber_kit-0.2.0 lib/kuber_kit/core/service_definition.rb
kuber_kit-0.1.9 lib/kuber_kit/core/service_definition.rb
kuber_kit-0.1.8 lib/kuber_kit/core/service_definition.rb
kuber_kit-0.1.7 lib/kuber_kit/core/service_definition.rb
kuber_kit-0.1.6 lib/kuber_kit/core/service_definition.rb
kuber_kit-0.1.5 lib/kuber_kit/core/service_definition.rb