Sha256: 37ae1d832d452417ff9ab2ade9d24de6ff7abd7e60f1e540e5af00bf0dd7157a

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require "set"
require "yaml"

module Glyptodont
  # Allow for configuring the tool
  class Configuration
    FILENAME = ".glyptodont.yaml"

    def initialize(directory)
      @config_filename = File.join(directory, FILENAME)
    end

    def ignore
      @ignore ||= extract_ignore_set || []
    end

    def threshold
      @threshold ||= config.fetch("threshold", nil)
    end

    def max_age_in_days
      @max_age_in_days ||= config.fetch("max_age_in_days", nil)
    end

    def keywords
      @keywords ||= config.fetch("keywords", nil)
    end

    private

    attr_reader :config_filename

    def config
      @config ||= if File.exist?(config_filename)
                    YAML.load_file(config_filename, fallback: {})
                  else
                    {}
                  end
    end

    def extract_ignore_set
      config.fetch("ignore", []).map do |line|
        parts = line.split(":", 2)
        {
          file: parts[0],
          line: parts[1].to_i
        }
      end.to_set
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glyptodont-0.3.0 lib/glyptodont/configuration.rb