Sha256: e31309a90a1b97539c3530518e5c90a793764a8833b2958ff353c3c1a5d595c8

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Vidar
  class Config
    DEFAULT_MANIFEST_FILE = "vidar.yml".freeze

    DEFAULT_OPTIONS = {
      compose_file:   -> { "docker-compose.ci.yml" },
      default_branch: -> { "master" },
      current_branch: -> { `git rev-parse --abbrev-ref HEAD`.strip.tr("/", "-") },
      revision:       -> { `git rev-parse HEAD`.strip },
      revision_name:  -> { `git show --pretty=format:"%s (%h)" -s HEAD`.strip },
      cluster:        -> { `kubectl config current-context`.strip.split("_", 4)[-1] } # TODO: improve context cleanup
    }.freeze

    class << self
      attr_reader :data
      attr_writer :manifest_file

      def load(file_path = manifest_file)
        @data = YAML.load_file(file_path)
        @loaded = true
      end

      def manifest_file
        @manifest_file || DEFAULT_MANIFEST_FILE
      end

      def loaded?
        @loaded
      end

      def get(key)
        load unless loaded?
        @data[key.to_s] || DEFAULT_OPTIONS[key.to_sym]&.call || fail(MissingConfigError, key)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vidar-0.1.5 lib/vidar/config.rb
vidar-0.1.4 lib/vidar/config.rb