buildr-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Boisvert <alex.boisv...@gmail.com>
Subject Re: Generating eclipse files for non-maven dependencies
Date Tue, 15 Sep 2009 05:05:03 GMT
On Mon, Sep 14, 2009 at 5:17 PM, Mat Schaffer <mat@schaffer.me> 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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message