Class: Herb::Embedded::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/herb/embedded/config.rb

Overview

Reads .herb.yml. The engine has no filesystem, so Ruby owns config entirely. Uses the same nested schema as upstream @herb-tools/config (only version, files.include/exclude, linter.fail_level, and linter.rules..enabled are read; other upstream keys are parsed as inert and ignored, not errored on).

Constant Summary collapse

CONFIG_FILENAME =
".herb.yml"
DEFAULT_INCLUDE_GLOBS =
["**/*.html.erb", "**/*.herb"].freeze
DEFAULT_EXCLUDE_GLOBS =
[].freeze
DEFAULT_FAIL_LEVEL =
:error

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Config

Returns a new instance of Config.



27
28
29
30
31
32
33
34
35
36
# File 'lib/herb/embedded/config.rb', line 27

def initialize(data)
  files = data["files"] || {}
  linter = data["linter"] || {}

  @include_globs = files["include"] || DEFAULT_INCLUDE_GLOBS.dup
  @exclude_globs = files["exclude"] || DEFAULT_EXCLUDE_GLOBS.dup
  @fail_level = (linter["fail_level"] || DEFAULT_FAIL_LEVEL).to_sym
  @linter_version = data["version"]
  @disabled_rule_names = disabled_rule_names(linter["rules"])
end

Instance Attribute Details

#exclude_globsObject (readonly)

Returns the value of attribute exclude_globs.



18
19
20
# File 'lib/herb/embedded/config.rb', line 18

def exclude_globs
  @exclude_globs
end

#fail_levelObject (readonly)

Returns the value of attribute fail_level.



18
19
20
# File 'lib/herb/embedded/config.rb', line 18

def fail_level
  @fail_level
end

#include_globsObject (readonly)

Returns the value of attribute include_globs.



18
19
20
# File 'lib/herb/embedded/config.rb', line 18

def include_globs
  @include_globs
end

#linter_versionObject (readonly)

Returns the value of attribute linter_version.



18
19
20
# File 'lib/herb/embedded/config.rb', line 18

def linter_version
  @linter_version
end

Class Method Details

.load(dir) ⇒ Object



20
21
22
23
24
25
# File 'lib/herb/embedded/config.rb', line 20

def self.load(dir)
  path = File.join(dir, CONFIG_FILENAME)
  data = File.exist?(path) ? (YAML.load_file(path) || {}) : {}

  new(data)
end

Instance Method Details

#enabled_rule_names(all_rule_names) ⇒ Object



38
39
40
# File 'lib/herb/embedded/config.rb', line 38

def enabled_rule_names(all_rule_names)
  all_rule_names - @disabled_rule_names
end