Sha256: 49019c278187f03835c4cfca52835d330212ba4ebfec233db4231c7dd17b44c9

Contents?: true

Size: 710 Bytes

Versions: 4

Compression:

Stored size: 710 Bytes

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)
    )
  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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kuber_kit-0.1.3 lib/kuber_kit/core/service_definition.rb
kuber_kit-0.1.2 lib/kuber_kit/core/service_definition.rb
kuber_kit-0.1.1 lib/kuber_kit/core/service_definition.rb
kuber_kit-0.1.0 lib/kuber_kit/core/service_definition.rb