On Mon, Sep 14, 2009 at 5:17 PM, Mat Schaffer <[email protected]> wrote:
> Right on. I didn't notice the write function. It's that Buildr.write? I see
> a handful of "def write"s in the project.
>
write() comes from buildr/core/common.rb but it doesn't appear to show up in
the rdoc :(
it's one of the many little (overlooked?) utility functions that make buildr
nice to use...
# :call-seq:
# write(name, content)
# write(name) { ... }
#
# Write the contents into a file. The second form calls the block and
writes the result.
#
# For example:
# write 'TIMESTAMP', Time.now
# write('TIMESTAMP') { Time.now }
#
# Yields to the block before writing the file, so you can chain read and
write together.
# For example:
# write('README') { read('README').sub("${build}", Time.now) }
def write(name, content = nil)
mkpath File.dirname(name)
content = yield if block_given?
File.open(name.to_s, 'wb') { |file| file.write content.to_s }
content.to_s
end
alex