Class: Waff::Config
- Inherits:
-
Object
- Object
- Waff::Config
- Defined in:
- lib/waff/config.rb
Constant Summary collapse
- REMOTE_NOT_FOUND =
<<-EOF Can't find owner and repository. Make sure the remote name is correctly set on the configuration file. EOF
Class Method Summary collapse
Class Method Details
.get_owner_and_repo ⇒ Object
20 21 22 23 |
# File 'lib/waff/config.rb', line 20 def get_owner_and_repo url = `git config --get remote.#{remote}.url`.strip url[/:(.*)\.git/, 1] || raise(REMOTE_NOT_FOUND) end |
.init_config! ⇒ Object
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 51 |
# File 'lib/waff/config.rb', line 25 def init_config! return if File.exist?(CONFIG_FILE) puts "No config file detected (#{CONFIG_FILE}). Will generate one now in current directory." print 'Github username: ' user = $stdin.gets print 'Github password/personal token: ' token = $stdin.gets print 'Git remote (leave empty for "origin"): ' remote = $stdin.gets.strip remote = remote.empty? ? 'origin' : remote # Write config file File.open(CONFIG_FILE, 'w') do |file| file.puts "user: #{user}" file.puts "token: #{token}" file.puts "remote: #{remote}" end # Write exclude file FileUtils.mkdir_p(File.dirname(EXCLUDE_FILE)) File.open(EXCLUDE_FILE, 'a+') do |file| unless file.read =~ /^#{CONFIG_FILE}$/ file.puts CONFIG_FILE end end end |
.remote ⇒ Object
16 17 18 |
# File 'lib/waff/config.rb', line 16 def remote config['remote'] end |
.token ⇒ Object
12 13 14 |
# File 'lib/waff/config.rb', line 12 def token config['token'] end |
.user ⇒ Object
8 9 10 |
# File 'lib/waff/config.rb', line 8 def user config['user'] end |