class Codeqa::Installer

Public Class Methods

call(app_root) click to toggle source
# File lib/codeqa/installer.rb, line 5
def self.call(app_root)
  new(app_root).call
end
new(app_root) click to toggle source
# File lib/codeqa/installer.rb, line 9
def initialize(app_root)
  @app_root=Pathname.new(File.expand_path(app_root))
end

Public Instance Methods

call() click to toggle source
# File lib/codeqa/installer.rb, line 13
def call
  generate_dot_codeqa
  install_codeqa_git_hook
end

Private Instance Methods

app_path(*args) click to toggle source
# File lib/codeqa/installer.rb, line 23
def app_path(*args)
  @app_root.join(*args)
end
dot_path(*args) click to toggle source
# File lib/codeqa/installer.rb, line 19
def dot_path(*args)
  app_path('.codeqa').join(*args)
end
generate_dot_codeqa() click to toggle source
# File lib/codeqa/installer.rb, line 46
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
install_codeqa_git_hook() click to toggle source
# File lib/codeqa/installer.rb, line 32
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
template_path(*args) click to toggle source
# File lib/codeqa/installer.rb, line 28
def template_path(*args)
  Codeqa.root.join('lib', 'templates').join(*args)
end