lib/inochi/generate.rb
##
# Writes the given contents to the file at the given
# path.  If the given path already exists, then a
# backup is created before invoking the given block.
#
Writes the given contents to the file at the given
path.  If the given path already exists, then a
backup is created before invoking the given block.
Writes the given contents to the file at the given path . If the given path already exists then a backup is created before invoking the given block .
def generate path, content 
      if File.exist? path
        old_digest = Digest::SHA1.digest(File.read(path))
        new_digest = Digest::SHA1.digest(content)
        if old_digest == new_digest
          notify :skip, path
        else
          notify :update, path
          cur, old, new = path, "#{path}.old", "#{path}.new"
          FileUtils.cp cur, old, :preserve => true
          File.write new, content
          yield old, new, cur if block_given?
        end
      else
        notify :create, path
        FileUtils.mkdir_p File.dirname(path)
        File.write path, content
      end
    end
def generate path , content if File . exist? path old_digest = Digest :: SHA1 . digest ( File . read ( path ) ) new_digest = Digest :: SHA1 . digest ( content ) if old_digest == new_digest notify :skip , path else notify :update , path cur , old , new = path , "#{path}.old" , "#{path}.new" FileUtils . cp cur , old , :preserve => true File . write new , content yield old , new , cur if block_given? end else notify :create , path FileUtils . mkdir_p File . dirname ( path ) File . write path , content end end
Writes the given contents to the file at the given
path.
Writes the given contents to the file at the given path .
# :yields: old_file, new_file, output_file
path
content