# encoding: utf-8 # frozen_string_literal: true require "yaml" module Carbon module Compiler class Metanostic # Deals with loading default of metanostics. It mostly takes defaults # from a defaults.yml file in the same directory as this file. module Defaults # Load a file and return the metanostics contained within the files. # # @param file [String] The file to load from. The file must contain # a YAML-formatted list of diagnostics. # @return [{String => Metanostic}] def self.load_file(file) data = YAML.load_file(file) metanostics = {} data["metanostics"].each do |name, metanostic| meta = { name: name, default: Mode.from(metanostic["default"]), allowed: Mode.from(metanostic["allowed"]), message: metanostic["message"] } metanostics[name] = Metanostic.new(meta) end metanostics end # Returns a frozen hash of all the default metanostics. Since it is # frozen, it is cached. # # @return [{String => Metanostic}] def self.defaults @_defaults ||= load_file(::File.expand_path("../defaults.yml", __FILE__)).freeze end end end end end