class Commands::Track::Command

Attributes

api_endpoint[R]
tracks[R]
tracks_yaml[R]

Public Class Methods

new(args = [], options = {}, config = {}, api_endpoint = Octokit::Default::API_ENDPOINT, tracks_yaml = " click to toggle source
Calls superclass method
# File lib/commands/track/command.rb, line 13
def initialize(args = [],
               options = {},
               config = {},
               api_endpoint = Octokit::Default::API_ENDPOINT,
               tracks_yaml = "#{__dir__}/../../../../../../tracks/tracks.yml")
  super(args, options, config)

  @tracks_yaml = tracks_yaml

  @api_endpoint = api_endpoint
  raise TracksFileNotFoundError.new(path: tracks_yaml) unless File.exist?(tracks_yaml)

  @tracks = load_tracks(YAML.safe_load(File.read(tracks_yaml))['tracks'])
end

Public Instance Methods

error_for(error) click to toggle source
# File lib/commands/track/command.rb, line 59
def error_for(error)
  mapped_errors = { Octokit::Unauthorized => CredentialsError,
                    Octokit::InvalidRepository => InvalidForkFormatError }

  mapped_errors[error.class] || error
end
list() click to toggle source
# File lib/commands/track/command.rb, line 30
def list
  Dir.chdir(tracks_dir) do
    track_names = tracks.keys
    say "Available Tracks:\n #{track_names.join("\n")}"
  end
end
start(track_name) click to toggle source
# File lib/commands/track/command.rb, line 39
def start(track_name)
  Dir.chdir(tracks_dir) do
    setup!(track_name)

    project = create_project("Learn #{track_name}")

    columns = create_columns(project.id, %w[TODO in-progress done])

    create_exercises(columns['TODO'], track_name)

    say ok "Project '#{project.name}' created: #{project.html_url}"
  end
rescue StandardError => e
  raise error_for(e)
end