aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominyk Tiller2016-02-16 16:34:51 +0000
committerDominyk Tiller2016-02-21 04:22:23 +0000
commitff4d16deebaabc374f4dae2786bd01e2865875a4 (patch)
tree8f730ca7367adaa521aafadf6624d16ae15457b7
parent7c9dff1f1ee34e5dac6d031cf167fdc07ccd86bf (diff)
downloadbrew-ff4d16deebaabc374f4dae2786bd01e2865875a4.tar.bz2
pathname: add append_lines method
* Blocks writing of new files via accidental typos, etc, which the normal open("blah", "a") doesn't. * Where files don't exist they should ideally be using `(buildpath/"dog").write` instead of open("blah", "a") already. * It's a bit less cluttered looking if you need several writes to different files in the formula, IMO.
-rw-r--r--Library/Homebrew/extend/pathname.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index c6b575c03..68115632d 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -131,6 +131,12 @@ class Pathname
open("w", *open_args) { |f| f.write(content) }
end
+ # Only appends to a file that is already created.
+ def append_lines(content, *open_args)
+ raise "Cannot append file that doesn't exist: #{self}" unless exist?
+ open("a", *open_args) { |f| f.puts(content) }
+ end
+
def binwrite(contents, *open_args)
open("wb", *open_args) { |f| f.write(contents) }
end unless method_defined?(:binwrite)