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-3.7.0 lib/krane/label_selector.rb
krane-3.6.2 lib/krane/label_selector.rb
krane-3.6.1 lib/krane/label_selector.rb
krane-3.5.2 lib/krane/label_selector.rb
krane-3.5.1 lib/krane/label_selector.rb
krane-3.5.0 lib/krane/label_selector.rb
krane-3.4.2 lib/krane/label_selector.rb
krane-3.4.1 lib/krane/label_selector.rb
krane-3.4.0 lib/krane/label_selector.rb
krane-3.3.0 lib/krane/label_selector.rb
krane-3.2.0 lib/krane/label_selector.rb
krane-3.1.0 lib/krane/label_selector.rb
krane-3.0.1 lib/krane/label_selector.rb
krane-3.0.0 lib/krane/label_selector.rb
krane-2.4.9 lib/krane/label_selector.rb
krane-2.4.8 lib/krane/label_selector.rb
krane-2.4.7 lib/krane/label_selector.rb
krane-2.4.6 lib/krane/label_selector.rb
krane-2.4.5 lib/krane/label_selector.rb
krane-2.4.4 lib/krane/label_selector.rb