Class: LearnCreate

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

Instance Method Summary collapse

Constructor Details

#initializeLearnCreate

Returns a new instance of LearnCreate.



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
64
65
66
67
68
# File 'lib/learn_create.rb', line 10

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 = ''

  loop do
    puts 'What is the name of the repository you would like to create?'
    @repo_name = gets.chomp
    url = 'https://api.github.com/repos/learn-co-curriculum/' + @repo_name
    encoded_url = URI.encode(url).slice(0, url.length)

    # Will hit rate limint 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)/
    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
      puts 'I am sorry, something went wrong, please start over'

    end

  else

    create_local_lesson('readme')

  end

  create_new_repo
end