Method: Hanami::Utils::Files.append

Defined in:
lib/hanami/utils/files.rb

.append(path, contents) ⇒ Object

Adds a new line at the bottom of the file

Parameters:

  • path (String, Pathname)

    the path to file

  • contents (String)

    the contents to add

Raises:

  • (Errno::ENOENT)

    if the path doesn’t exist

See Also:

Since:

  • 1.1.0

[View source]

146
147
148
149
150
151
152
153
154
# File 'lib/hanami/utils/files.rb', line 146

def self.append(path, contents)
  mkdir_p(path)

  content = ::File.readlines(path)
  content << "\n" if _append_newline?(content)
  content << "#{contents}\n"

  write(path, content)
end