Class: OvercommitConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/overcommit_config.rb

Instance Method Summary collapse

Instance Method Details

#generate_configObject

Generate popular config for Overcommit. Run overcommit_config to generate .overcommit.yml file.



6
7
8
9
10
11
12
13
14
15
# File 'lib/overcommit_config.rb', line 6

def generate_config
  puts "Generating overcommit config ..."
  file_name = ".overcommit.yml"
  config_file = File.expand_path File.dirname(__FILE__) + '/.overcommit_popular_config.yml'
  config = YAML.safe_load(ERB.new(File.read(config_file)).result)
  File.open(file_name, "w") { |f| f << config.to_yaml }
  generate_rubo_script
  install_overcommit
  update_overcommit_config
end

#generate_rubo_scriptObject



17
18
19
20
21
22
23
24
# File 'lib/overcommit_config.rb', line 17

def generate_rubo_script
  puts "Generating overcommit rubocop executable script ..."
  file_name = "./bin/custom-rubocop-script"
  script_file = File.expand_path File.dirname(__FILE__) + '/custom-rubocop-script'
  config = ERB.new(File.read(script_file)).result
  File.open(file_name, "w") { |f| f << config }
  FileUtils.chmod("a+x", file_name)
end

#install_overcommitObject

Install Overcommit hooks in current app



32
33
34
# File 'lib/overcommit_config.rb', line 32

def install_overcommit
  exec 'overcommit --install' rescue nil
end

#update_overcommit_configObject

Update overcommit config



27
28
29
# File 'lib/overcommit_config.rb', line 27

def update_overcommit_config
  exec 'overcommit --sign' rescue nil
end