Class: TeachersPet::Actions::Base
- Inherits:
-
Object
- Object
- TeachersPet::Actions::Base
- Defined in:
- lib/teachers_pet/actions/base.rb
Direct Known Subclasses
AddToTeam, CloneRepos, CreateRepos, CreateStudentTeams, ForkCollab, OpenIssue, PushFiles
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #init_client ⇒ Object
-
#initialize(opts = {}) ⇒ Base
constructor
A new instance of Base.
- #octokit_config ⇒ Object
- #read_file(filename) ⇒ Object
- #read_students_file ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Base
Returns a new instance of Base.
10 11 12 |
# File 'lib/teachers_pet/actions/base.rb', line 10 def initialize(opts={}) = opts.symbolize_keys end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/teachers_pet/actions/base.rb', line 8 def client @client end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/teachers_pet/actions/base.rb', line 8 def end |
Instance Method Details
#init_client ⇒ Object
34 35 36 37 38 39 |
# File 'lib/teachers_pet/actions/base.rb', line 34 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
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/teachers_pet/actions/base.rb', line 14 def octokit_config opts = { api_endpoint: self.[:api], web_endpoint: self.[:web], login: self.[:username], # Organizations can get big, pull in all pages auto_paginate: true } if self.[:token] opts[:access_token] = self.[:token] elsif self.[:password] opts[:password] = self.[:password] else raise Thor::RequiredArgumentMissingError.new("No value provided for option --password or --token") end opts end |
#read_file(filename) ⇒ Object
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 69 |
# File 'lib/teachers_pet/actions/base.rb', line 41 def read_file(filename) map = Hash.new File.open(filename).each_line do |team| # Team can be a single user, or a team name and multiple users # Trim whitespace, otherwise issues occur 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_students_file ⇒ Object
71 72 73 74 75 |
# File 'lib/teachers_pet/actions/base.rb', line 71 def read_students_file student_file = self.[:students] puts "Loading students:" read_file(student_file) end |