Sha256: 70ae474d461d1a38e712dabfa601b68bc5a06a26e69bad936f9a1fa995d98b2a

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module Pronto
  class ConfigFile
    EMPTY = {
      'all' => {
        'exclude' => [],
        'include' => []
      },
      'github' => {
        'slug' => nil,
        'access_token' => nil,
        'api_endpoint' => 'https://api.github.com/',
        'web_endpoint' => 'https://github.com/'
      },
      'gitlab' => {
        'slug' => nil,
        'api_private_token' => nil,
        'api_endpoint' => 'https://gitlab.com/api/v3'
      },
      'bitbucket' => {
        'slug' => nil,
        'username' => nil,
        'password' => nil,
        'web_endpoint' => 'https://bitbucket.org/'
      },
      'runners' => [],
      'formatters' => [],
      'max_warnings' => nil,
      'verbose' => false
    }.freeze

    def initialize(path = '.pronto.yml')
      @path = path
    end

    def to_h
      hash = File.exist?(@path) ? YAML.load_file(@path) : {}
      deep_merge(hash)
    end

    private

    def deep_merge(hash)
      merger = proc do |_, oldval, newval|
        if oldval.is_a?(Hash) && newval.is_a?(Hash)
          oldval.merge(newval, &merger)
        else
          oldval || newval
        end
      end

      hash.merge(EMPTY, &merger)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pronto-0.8.2 lib/pronto/config_file.rb
pronto-0.8.1 lib/pronto/config_file.rb