Class: Ruboclean::ToYamlConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboclean/to_yaml_converter.rb

Overview

Converts the configuration hash to YAML and applies modifications on it, if requested

Instance Method Summary collapse

Constructor Details

#initialize(configuration_hash, preserve_comments, source_yaml) ⇒ ToYamlConverter

Returns a new instance of ToYamlConverter.



6
7
8
9
10
# File 'lib/ruboclean/to_yaml_converter.rb', line 6

def initialize(configuration_hash, preserve_comments, source_yaml)
  @configuration_hash = configuration_hash
  @preserve_comments = preserve_comments
  @source_yaml = source_yaml
end

Instance Method Details

#to_yamlObject



12
13
14
15
16
17
18
# File 'lib/ruboclean/to_yaml_converter.rb', line 12

def to_yaml
  target_yaml = sanitize_yaml(configuration_hash.transform_keys(&:to_s).to_yaml)

  return target_yaml unless preserve_comments?

  preserve_preceding_comments(source_yaml, target_yaml)
end