Method: App::Replacer.replace_yml

Defined in:
lib/core/replacer.rb

.replace_yml(path_and_file, data) ⇒ Object

Takes file path and returns array of lines (that can then be used to write same/new file).

Raises:

  • (RuntimeError)


180
181
182
183
184
185
186
187
188
189
# File 'lib/core/replacer.rb', line 180

def self.replace_yml(path_and_file, data)
    raise RuntimeError, "Expected String, instead got #{path_and_file.class}" unless path_and_file.is_a?(String)
    raise RuntimeError, "Expected Hash, instead got #{data.class}" unless data.is_a?(Hash)
    extension = Blufin::Files::extract_file_name(path_and_file).split('.')
    extension = extension[extension.length - 1].downcase
    raise RuntimeError, "Expected YML file, instead got: #{path_and_file}" unless %w(yml yaml).include?(extension)
    new_lines = []
    scan_file(path_and_file, OP_REPLACE, data: data, new_lines: new_lines)
    new_lines
end