Sha256: 2cef831a7ff4cd5d899bcc2ca567113241692a3edeecaed3edd11da9714670c5

Contents?: true

Size: 856 Bytes

Versions: 11

Compression:

Stored size: 856 Bytes

Contents

require 'yaml'

module Fasterer
  class Config
    FILE_NAME         = '.fasterer.yml'
    SPEEDUPS_KEY      = 'speedups'
    EXCLUDE_PATHS_KEY = 'exclude_paths'

    def ignored_speedups
      @ignored_speedups ||=
        file[SPEEDUPS_KEY].select { |_, value| value == false }.keys.map(&:to_sym)
    end

    def ignored_files
      @ignored_files ||=
        file[EXCLUDE_PATHS_KEY].flat_map { |path| Dir[path] }
    end

    def file
      @file ||= begin
        return nil_file unless File.exist?(FILE_NAME)
        # Yaml.load_file returns false if the content is blank
        loaded = YAML.load_file(FILE_NAME) || nil_file
        # if the loaded file misses any of the two keys.
        loaded.merge!(nil_file) { |_k, v1, v2| v1 || v2 }
      end
    end

    def nil_file
      { SPEEDUPS_KEY => {}, EXCLUDE_PATHS_KEY => [] }
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fasterer-0.5.1 lib/fasterer/config.rb
fasterer-0.5.0 lib/fasterer/config.rb
fasterer-0.4.2 lib/fasterer/config.rb
fasterer-0.4.1 lib/fasterer/config.rb
fasterer-0.4.0 lib/fasterer/config.rb
fasterer-0.3.2 lib/fasterer/config.rb
fasterer-0.3.1 lib/fasterer/config.rb
fasterer-0.3.0 lib/fasterer/config.rb
fasterer-0.2.1 lib/fasterer/config.rb
fasterer-0.2.0 lib/fasterer/config.rb
fasterer-0.1.12 lib/fasterer/config.rb