Sha256: 2fb7562f42c37e7638300de15282662827ba2e4c17a456d3f77b58e8a622f154

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

require 'yaml'
require 'thor/core_ext/hash_with_indifferent_access'

module Gitx
  class Configuration
    CONFIG_FILE = '.gitx.yml'.freeze

    attr_reader :config

    def initialize(root_dir)
      @config = Thor::CoreExt::HashWithIndifferentAccess.new
      @config.merge!(load_config(File.join(__dir__, 'defaults.yml')))
      @config.merge!(load_config(File.join(root_dir, CONFIG_FILE)))
    end

    def base_branch
      config[:base_branch]
    end

    def release_label
      config[:release_label]
    end

    def aggregate_branches
      config[:aggregate_branches]
    end

    def aggregate_branch?(branch)
      aggregate_branches.include?(branch)
    end

    def reserved_branches
      config[:reserved_branches]
    end

    def reserved_branch?(branch)
      reserved_branches.include?(branch)
    end

    def taggable_branches
      config[:taggable_branches]
    end

    def taggable_branch?(branch)
      taggable_branches.include?(branch)
    end

    def update_from_base_on_release?
      config.fetch(:update_from_base_on_release, true)
    end

    def after_release_scripts
      config[:after_release]
    end

    private

    # load configuration file
    def load_config(path)
      if File.exist?(path)
        ::YAML.load_file(path)
      else
        {}
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gitx-4.5.0 lib/gitx/configuration.rb
gitx-4.4.0 lib/gitx/configuration.rb
gitx-4.3.0 lib/gitx/configuration.rb