Sha256: 2687fc0ff6a184ebfb4471f7021e19caf6f60362234d6ece2d8a9ad406ef5060

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require 'fileutils'

module Codeqa
  class Installer
    def self.call(app_root)
      new(app_root).call
    end

    def initialize(app_root)
      @app_root=Pathname.new(File.expand_path(app_root))
    end

    def call
      generate_dot_codeqa
      install_codeqa_git_hook
    end

    private
    def dot_path(*args)
      app_path('.codeqa').join(*args)
    end

    def app_path(*args)
      @app_root.join(*args)
    end

    private
    def template_path(*args)
      Codeqa.root.join('lib', 'templates').join(*args)
    end

    def install_codeqa_git_hook
      git_root = app_path.join(".git")
      pre_commit_path = git_root.join 'hooks', 'pre-commit'

      return false unless File.exist?(git_root)
      return false if File.exist?(pre_commit_path)

      FileUtils.mv(pre_commit_path,
                   git_root.join('hooks', 'pre-commit.bkp'),
                   :force => true)
      pre_commit_path.make_symlink('../../.codeqa/git_hook.rb') #relative path!
      true
    end

    def generate_dot_codeqa
      dot_path.mkdir unless dot_path.exist?
      dot_path("hooks").mkdir unless dot_path("hooks").exist?
      FileUtils.cp(template_path('base_hook.rb'), dot_path("hooks","base.rb")) unless dot_path("hooks","base.rb").exist?
      FileUtils.cp(template_path('git_hook.rb'), dot_path("git_hook.rb")) unless  dot_path("git_hook.rb").exist?
      dot_path("git_hook.rb").chmod(0775)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codeqa-0.5.0 lib/codeqa/installer.rb