Class: AnnotateRb::ConfigGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/annotate_rb/config_generator.rb

Class Method Summary collapse

Class Method Details

.default_config_ymlObject



22
23
24
25
# File 'lib/annotate_rb/config_generator.rb', line 22

def default_config_yml
  defaults_hash = Options.from({}, {}).to_h
  _yml_content = YAML.dump(defaults_hash, StringIO.new).string
end

.unset_config_defaultsObject

Returns unset configuration key-value pairs as yaml. Useful when a config file was generated an older version of gem and new

settings get added.


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/annotate_rb/config_generator.rb', line 9

def unset_config_defaults
  user_defaults = ConfigLoader.load_config
  defaults = Options.from({}, {}).to_h

  differences = defaults.keys - user_defaults.keys
  result = defaults.slice(*differences)

  # Generates proper YAML including the leading hyphens `---` header
  yml_content = YAML.dump(result, StringIO.new).string
  # Remove the header
  yml_content.sub("---", "")
end