Method: Hanami::Utils::Files.remove_line

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

.remove_line(path, target) ⇒ Object

Removes line from ‘path`, matching `target`.

Parameters:

  • path (String, Pathname)

    the path to file

  • target (String, Regexp)

    the target to remove

Raises:

  • (Errno::ENOENT)

    if the path doesn’t exist

  • (ArgumentError)

    if ‘target` cannot be found in `path`

Since:

  • 1.1.0

[View source]

276
277
278
279
280
281
282
# File 'lib/hanami/utils/files.rb', line 276

def self.remove_line(path, target)
  content = ::File.readlines(path)
  i       = index(content, path, target)

  content.delete_at(i)
  write(path, content)
end