Sha256: 12e2269b623d15c2afa6a559e11b20a357c03e109dbc0b5945b8a2e30628bb3e

Contents?: true

Size: 911 Bytes

Versions: 9

Compression:

Stored size: 911 Bytes

Contents

# frozen_string_literal: true

require 'delegate'

module Chutney
  # gherkin_lint configuration object
  class Configuration < SimpleDelegator
    def initialize(path)
      @path = path
      @config = load_configuration || {}
      load_user_configuration
      super(@config)
    end

    def configuration_path
      @path
    end

    def load_configuration
      YAML.load_file configuration_path || '' if configuration_path
    end

    def load_user_configuration
      config_files = ['chutney.yml', '.chutney.yml'].map do |fname|
        Dir.glob(File.join(Dir.pwd, '**', fname))
      end.flatten

      config_file = config_files.first
      merge_config(config_file) if !config_file.nil? && File.exist?(config_file)
    end

    private

    def merge_config(config_file)
      @config.merge!(YAML.load_file(config_file)) { |_k, old, new| old.merge!(new) } unless @config.empty?
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
chutney-3.6.0 lib/chutney/configuration.rb
chutney-3.5.0 lib/chutney/configuration.rb
chutney-3.3.0 lib/chutney/configuration.rb
chutney-3.2.1 lib/chutney/configuration.rb
chutney-3.2.0 lib/chutney/configuration.rb
chutney-3.1.1 lib/chutney/configuration.rb
chutney-3.1.0 lib/chutney/configuration.rb
chutney-3.0.1 lib/chutney/configuration.rb
chutney-3.0.0 lib/chutney/configuration.rb