Sha256: becd469bf0709f83c582bca412cf31de35c3419e545fbca345a7bc0044687c56

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 KB

Contents

# encoding: utf-8

require "erb"
require "fileutils"
require "nake/task"

# nake hooks:whitespace:install
# nake hooks:whitespace:install --force
# nake hooks:whitespace:install --path=script
# nake hooks:whitespace:install --encoding=utf-8
# nake hooks:whitespace:install --whitelist=pattern
# nake hooks:whitespace:install --blacklist=pattern
Nake::Task.new("hooks:whitespace:install") do |task|
  task.config.declare(:path, :encoding, :whitelist, :blacklist)
  task.description = "Install hook for automatically removing trailing whitespace"
  task.define do |options = Hash.new|
    # --force
    if File.exist?(".git/hooks/pre-commit") && options[:force]
      FileUtils.rm ".git/hooks/pre-commit"
    end

    # --path=script
    options[:path] = task.config[:path] unless options[:path]

    # --encoding=utf-8
    options[:encoding] = task.config[:encoding] unless options[:encoding]

    # --whitelist=pattern
    options[:whitelist] = task.config[:whitelist] unless options[:whitelist]

    # --blacklist=pattern
    options[:blacklist] = task.config[:blacklist] unless options[:blacklist]

    if File.exist?(".git/hooks/pre-commit")
      abort "The hook .git/hooks/pre-commit already exists. Run this task with --force if you want to overwrite it."
    else
      begin
        puts "Installing .git/hooks/pre-commit ..."
        source = File.join(File.dirname(__FILE__), "..", "support", "pre-commit.erb")
        File.open(".git/hooks/pre-commit", "w") do |file|
          file.puts(ERB.new(File.read(source)).result(binding))
        end
        File.chmod(0755, ".git/hooks/pre-commit")
      rescue Errno::ENOENT
        abort "You have to run git init first!"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
code-cleaner-0.8.2 tasks/code-cleaner.nake
do_riak-0.10.1.pre gems/gems/code-cleaner-0.8.1/tasks/code-cleaner.nake
code-cleaner-0.8.1 tasks/code-cleaner.nake
code-cleaner-0.8 tasks/code-cleaner.nake