Module: Carbon::Compiler::Metanostic::Defaults

Defined in:
lib/carbon/compiler/metanostic/defaults.rb

Overview

Deals with loading default of metanostics. It mostly takes defaults from a defaults.yml file in the same directory as this file.

Class Method Summary collapse

Class Method Details

.defaults{String => Metanostic}

Returns a frozen hash of all the default metanostics. Since it is frozen, it is cached.

Returns:



34
35
36
37
# File 'lib/carbon/compiler/metanostic/defaults.rb', line 34

def self.defaults
  @_defaults ||=
    load_file(::File.expand_path("../defaults.yml", __FILE__)).freeze
end

.load_file(file) ⇒ {String => Metanostic}

Load a file and return the metanostics contained within the files.

Parameters:

  • file (String)

    The file to load from. The file must contain a YAML-formatted list of diagnostics.

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/carbon/compiler/metanostic/defaults.rb', line 16

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