Sha256: c89f3ecdf5a3b135ed93256f65523003cbab230c70c4b5a4e4f94b22102c808c

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carbon-compiler-0.2.0 lib/carbon/compiler/metanostic/defaults.rb