Module: GitmeTime::CLI::InitTutorial
- Defined in:
- lib/gitme_time/cli/init_tutorial.rb
Class Method Summary collapse
- .create_project_config_file ⇒ Object
- .generate_git_hook ⇒ Object
- .generate_project_config_file ⇒ Object
- .write_hook_file ⇒ Object
Class Method Details
.create_project_config_file ⇒ Object
5 6 7 8 |
# File 'lib/gitme_time/cli/init_tutorial.rb', line 5 def create_project_config_file generate_project_config_file generate_git_hook end |
.generate_git_hook ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gitme_time/cli/init_tutorial.rb', line 10 def generate_git_hook if File.file? Config.project_hook_file hook_content = File.open(Config.project_hook_file).read if hook_content =~ /GitmeTime/ version = hook_content.match(/GitmeTime (.+)\.$/)[1] if version == GitmeTime::VERSION puts 'Git post-commit hook already exists and is updated. Skipping ...' else File.delete Config.project_hook_file write_hook_file puts 'Generated an updated Git post-commit hook' end else puts 'Git post-commit hook already exists but it has not been generated by GitmeTime. What I have to do ?' option = nil while option.nil? print '[O]verwrite/[S]kip/Show [C]ontent ? ' option = STDIN.gets.chomp.downcase if option == 'i' puts 'Skipping Git post-commit hook generation...' break elsif option == 'o' File.delete Config.project_hook_file write_hook_file elsif option == 'c' puts puts hook_content puts option = nil else option = nil puts 'Invalid Option. Allowed choices are:' end end end else write_hook_file puts 'Generated the Git post-commit hook' end puts 'Init Completed!' end |
.generate_project_config_file ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gitme_time/cli/init_tutorial.rb', line 74 def generate_project_config_file if GitmeTime::Config.project_data? puts "Project config file already exists (#{GitmeTime::Config.project_config_file}). Skipping ..." else puts "Generating Project config file ..." config = { 'domain' => get_domain, 'project_id' => get_project, 'tag' => get_tag, 'track_empty_hours' => get_track_empty_hours } File.open Config.project_config_file, 'w' do |f| f.write(config.to_yaml) end puts "Project config file generated!" end end |
.write_hook_file ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gitme_time/cli/init_tutorial.rb', line 52 def write_hook_file File.open Config.project_hook_file, 'w' do |f| f.write <<-FILE #!/usr/bin/env ruby # # This file was generated by GitmeTime #{GitmeTime::VERSION}. # For more informations, see https://github.com/mikamai/gitme_time require 'pathname' ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../../Gemfile", Pathname.new(__FILE__).realpath) require 'rubygems' require 'bundler/setup' load Gem.bin_path('gitme_time', 'gitme_time') FILE end File.chmod 0755, Config.project_hook_file puts "Git post-commit hook successfully created in #{Config.project_hook_file}" end |