Class: LearnCreate
- Inherits:
-
Object
- Object
- LearnCreate
- Defined in:
- lib/learn_create.rb
Instance Method Summary collapse
-
#initialize ⇒ LearnCreate
constructor
A new instance of LearnCreate.
Constructor Details
#initialize ⇒ LearnCreate
Returns a new instance of LearnCreate.
6 7 8 9 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 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/learn_create.rb', line 6 def initialize puts 'Note: You must have write access to the learn-co-curriculum org on GitHub to use this tool' # Checks to see if chosen name already exists as a repository @repo_name = '' @ssh_configured = check_ssh_config loop do puts 'What is the name of the repository you would like to create?' @repo_name = gets.strip.gsub(/\s+/, '-').downcase url = 'https://api.github.com/repos/learn-co-curriculum/' + @repo_name encoded_url = URI.encode(url).slice(0, url.length) # Will hit rate limit on github is used too much check_existing = Faraday.get URI.parse(encoded_url) break if check_existing.body.include? '"Not Found"' puts 'A repository with that name already exists:' puts 'https://github.com/learn-co-curriculum/' + @repo_name puts '' end readme = '' loop do puts 'Is this a Readme? (y/n)' readme = gets.chomp.downcase break if readme =~ /^(y|n)/ || readme == '' puts 'Please enter yes or no' puts '' end # If not a readme, create language specific lab, otherwise create a standard readme if readme =~ /^n$/ language = choose_language case language when /^ru/ create_local_lesson('lab', 'Ruby') when /^j/ create_local_lesson('lab', 'JavaScript') when /^re/ create_local_lesson('lab', 'React') else create_local_lesson('readme') end else create_local_lesson('readme') end create_new_repo puts '' puts "Repository created. Navigate into #{@repo_name} or open https://github.com/learn-co-curriculum/#{@repo_name} to get started" end |