Class: Leftovers::ConfigLoader::DocumentSchema

Inherits:
ObjectSchema show all
Defined in:
lib/leftovers/config_loader/document_schema.rb

Constant Summary collapse

PRECOMPILERS =
%i{haml_paths slim_paths json_paths yaml_paths erb_paths}.freeze

Class Method Summary collapse

Methods inherited from ObjectSchema

attribute, attributes, inherit_attributes_from, require_groups, validate

Methods inherited from Schema

===, error, validate

Class Method Details

.to_ruby(node) ⇒ Object

rubocop:disable Metrics



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/leftovers/config_loader/document_schema.rb', line 23

def self.to_ruby(node) # rubocop:disable Metrics
  read_hash = super
  write_hash = read_hash.dup

  read_hash.each do |key, value|
    next unless PRECOMPILERS.include?(key)

    value = { paths: value, format: key.to_s.delete_suffix('_paths').to_sym }
    yaml = { 'precompile' => [value.transform_keys(&:to_s).transform_values(&:to_s)] }
      .to_yaml.delete_prefix("---\n")

    ::Leftovers.warn(<<~MESSAGE)
      \e[33m`#{key}:` is deprecated\e[0m
      Replace with:
      \e[32m#{yaml}\e[0m
    MESSAGE

    write_hash[:precompile] = ::Leftovers.wrap_array(write_hash[:precompile])
    write_hash[:precompile] << value
    write_hash.delete(key)
  end

  write_hash
end