Sha256: 6bb89e3558e908f3e180eba129a469b63d831aaabfbe76b2ee7873fc8bd8798f

Contents?: true

Size: 931 Bytes

Versions: 6

Compression:

Stored size: 931 Bytes

Contents

class KuberKit::Core::Service
  AttributeNotSet = Class.new(Indocker::Error)

  attr_reader :name, :template_name, :tags, :images, :attributes

  Contract KeywordArgs[
    name:           Symbol,
    template_name:  Symbol,
    tags:           ArrayOf[Symbol],
    images:         ArrayOf[Symbol],
    attributes:     HashOf[Symbol => Any],
  ] => Any
  def initialize(name:, template_name:, tags:, images:, attributes:)
    @name = name
    @template_name = template_name
    @tags = tags
    @images = images
    @attributes = attributes
  end

  def uri
    name.to_s.gsub("_", "-")
  end

  def attribute(attribute_name, default: nil)
    if !attributes.has_key?(attribute_name.to_sym) && default.nil?
      raise AttributeNotSet, "attribute #{attribute_name} was not set"
    end

    if !attributes.has_key?(attribute_name.to_sym) && !default.nil?
      return default
    end

    attributes[attribute_name.to_sym]
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kuber_kit-0.2.3 lib/kuber_kit/core/service.rb
kuber_kit-0.2.2 lib/kuber_kit/core/service.rb
kuber_kit-0.2.1 lib/kuber_kit/core/service.rb
kuber_kit-0.2.0 lib/kuber_kit/core/service.rb
kuber_kit-0.1.9 lib/kuber_kit/core/service.rb
kuber_kit-0.1.8 lib/kuber_kit/core/service.rb