Class: TeachersPet::Actions::Base
- Inherits:
-
Object
- Object
- TeachersPet::Actions::Base
show all
- Defined in:
- lib/teachers_pet/actions/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Base
Returns a new instance of Base.
11
12
13
|
# File 'lib/teachers_pet/actions/base.rb', line 11
def initialize(opts={})
@options = opts.symbolize_keys
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
9
10
11
|
# File 'lib/teachers_pet/actions/base.rb', line 9
def client
@client
end
|
#options ⇒ Object
Returns the value of attribute options.
9
10
11
|
# File 'lib/teachers_pet/actions/base.rb', line 9
def options
@options
end
|
Instance Method Details
#execute(command) ⇒ Object
94
95
96
|
# File 'lib/teachers_pet/actions/base.rb', line 94
def execute(command)
return system(command)
end
|
#init_client ⇒ Object
45
46
47
48
49
50
|
# File 'lib/teachers_pet/actions/base.rb', line 45
def init_client
puts "=" * 50
puts "Authenticating to GitHub..."
octokit = Octokit::Client.new(self.octokit_config)
@client = TeachersPet::ClientDecorator.new(octokit)
end
|
#octokit_config ⇒ Object
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
|
# File 'lib/teachers_pet/actions/base.rb', line 15
def octokit_config
opts = {
api_endpoint: self.options[:api],
web_endpoint: self.options[:web],
login: self.options[:username],
auto_paginate: true
}
if self.options[:token]
if self.options[:token].eql?('token')
print 'Please enter your GitHub token: '
opts[:access_token] = STDIN.noecho(&:gets).chomp
else
opts[:access_token] = self.options[:token]
end
elsif self.options[:password]
if self.options[:password].eql?('password')
print 'Please enter your GitHub password: '
opts[:password] = STDIN.noecho(&:gets).chomp
else
opts[:password] = self.options[:password]
end
else
raise Thor::RequiredArgumentMissingError.new("No value provided for option --password or --token")
end
opts
end
|
#read_file(filename) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/teachers_pet/actions/base.rb', line 52
def read_file(filename)
map = Hash.new
File.open(filename).each_line do |team|
team.strip!
items = team.split(' ')
items.each do |item|
abort("No users can be named 'owners' (in any case)") if 'owners'.eql?(item.downcase)
end
if map[items[0]].nil?
map[items[0]] = Array.new
puts " -> #{items[0]}"
if (items.size > 1)
print " \\-> members: "
1.upto(items.size - 1) do |i|
print "#{items[i]} "
map[items[0]] << items[i]
end
print "\n"
else
map[items[0]] << items[0]
end
end
end
map
end
|
#read_members_file ⇒ Object
88
89
90
91
92
|
# File 'lib/teachers_pet/actions/base.rb', line 88
def read_members_file
file = self.options[:members]
puts "Loading members to add:"
read_file(file).keys
end
|
#read_students_file ⇒ Object
82
83
84
85
86
|
# File 'lib/teachers_pet/actions/base.rb', line 82
def read_students_file
student_file = self.options[:students]
puts "Loading students:"
read_file(student_file)
end
|