Sha256: c362044e1b837e123b1f3a065d1356fb1f5a659961d630ebbd190c548fc4645e

Contents?: true

Size: 775 Bytes

Versions: 58

Compression:

Stored size: 775 Bytes

Contents

# frozen_string_literal: true

module Krane
  class LabelSelector
    def self.parse(string)
      selector = {}

      string.split(',').each do |kvp|
        key, value = kvp.split('=', 2)

        if key.blank?
          raise ArgumentError, "key is blank"
        end

        if key.end_with?("!")
          raise ArgumentError, "!= selectors are not supported"
        end

        if value&.start_with?("=")
          raise ArgumentError, "== selectors are not supported"
        end

        selector[key] = value
      end

      new(selector)
    end

    def initialize(hash)
      @selector = hash
    end

    def to_h
      @selector
    end

    def to_s
      return "" if @selector.nil?
      @selector.map { |k, v| "#{k}=#{v}" }.join(",")
    end
  end
end

Version data entries

58 entries across 58 versions & 3 rubygems

Version Path
krane-2.1.3 lib/krane/label_selector.rb
krane-2.1.2 lib/krane/label_selector.rb
krane-2.1.1 lib/krane/label_selector.rb
krane-2.1.0 lib/krane/label_selector.rb
krane-2.0.0 lib/krane/label_selector.rb
kubernetes-deploy-1.0.0.pre.2 lib/krane/label_selector.rb
krane-1.1.4 lib/krane/label_selector.rb
krane-1.1.3 lib/krane/label_selector.rb
krane-1.1.2 lib/krane/label_selector.rb
krane-1.1.1 lib/krane/label_selector.rb
krane-1.1.0 lib/krane/label_selector.rb
tobsch-krane-1.0.2 lib/krane/label_selector.rb
tobsch-krane-1.0.1 lib/krane/label_selector.rb
tobsch-krane-1.0.0 lib/krane/label_selector.rb
krane-1.0.0 lib/krane/label_selector.rb
kubernetes-deploy-1.0.0.pre.1 lib/krane/label_selector.rb
kubernetes-deploy-0.31.1 lib/krane/label_selector.rb
kubernetes-deploy-0.31.0 lib/krane/label_selector.rb