Class: LearnBase
- Inherits:
-
Object
show all
- Defined in:
- lib/learn-tool/learn-base.rb
Constant Summary
collapse
- GITHUB_ORG =
'https://api.github.com/repos/learn-co-curriculum/'
- README_TEMPLATE =
'readme-template'
- RUBY_LAB_TEMPLATE =
'ruby-lab-template'
- JAVASCRIPT_LAB_TEMPLATE =
'js-lab-template'
- REACT_LAB_TEMPLATE =
'react-lab-template'
Instance Method Summary
collapse
Constructor Details
#initialize(filepath) ⇒ LearnBase
Returns a new instance of LearnBase.
9
10
11
12
13
|
# File 'lib/learn-tool/learn-base.rb', line 9
def initialize(filepath)
@filepath = filepath
@old_repo_name = ''
@new_repo_name = ''
end
|
Instance Method Details
#cd_into_and(filepath, command) ⇒ Object
22
23
24
25
|
# File 'lib/learn-tool/learn-base.rb', line 22
def cd_into_and(filepath, command)
cmd = "cd #{filepath} && #{command}"
`#{cmd}`
end
|
#create_new_repo ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/learn-tool/learn-base.rb', line 52
def create_new_repo
puts 'Cloning old repository'
git_clone
puts ''
puts 'Creating new remote learn-co-curriculum repository'
git_create_and_set_new_origin
puts ''
puts 'Setting new git remote based on SSH settings'
git_set_remote
puts ''
puts 'Pushing all old-remote branches to new remote'
git_push
end
|
#end_message ⇒ Object
69
70
71
72
73
|
# File 'lib/learn-tool/learn-base.rb', line 69
def end_message
puts ''
puts 'To access local folder, change directory into ' + @new_repo_name + '/'
puts "Repository available at #{GITHUB_ORG}" + @new_repo_name
end
|
#get_new_name ⇒ Object
45
46
47
48
49
50
|
# File 'lib/learn-tool/learn-base.rb', line 45
def get_new_name
puts 'Note: You must have write access to the learn-co-curriculum org on GitHub to use this tool'
until name_new_repo do
puts 'Careful - rate limiting can occur'
end
end
|
#name_new_repo ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/learn-tool/learn-base.rb', line 27
def name_new_repo
puts 'What is the name of the repository you would like to create?'
new_name = gets.strip.gsub(/\s+/, '-').downcase
if name_length_is_good(new_name)
if repo_is_available(new_name)
@new_repo_name = new_name
else
puts 'A repository with that name already exists. Please try again.'
return false
end
else
puts 'Repository names must be shorter than 100 characters'
return false
end
@new_repo_name
end
|
#repo_is_available(repo_name) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/learn-tool/learn-base.rb', line 15
def repo_is_available(repo_name)
url = GITHUB_ORG + repo_name
encoded_url = URI.encode(url).slice(0, url.length)
check_existing = Faraday.get URI.parse(encoded_url)
check_existing.body.include? '"Not Found"'
end
|