Method: Hanami::Utils::Files.unshift

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

.unshift(path, line) ⇒ Object

Adds a new line at the top of the file

Parameters:

  • path (String, Pathname)

    the path to file

  • line (String)

    the line to add

Raises:

  • (Errno::ENOENT)

    if the path doesn’t exist

See Also:

Since:

  • 1.1.0

[View source]

129
130
131
132
133
134
# File 'lib/hanami/utils/files.rb', line 129

def self.unshift(path, line)
  content = ::File.readlines(path)
  content.unshift("#{line}\n")

  write(path, content)
end