Class: Commands::Track::Command

Inherits:
Thor
  • Object
show all
Defined in:
lib/commands/track/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}, api_endpoint = Octokit::Default::API_ENDPOINT, tracks_yaml = "#{__dir__}/../../../../../../tracks/tracks.yml") ⇒ Command

Returns a new instance of Command.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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

Instance Attribute Details

#api_endpointObject (readonly)

Returns the value of attribute api_endpoint.



11
12
13
# File 'lib/commands/track/command.rb', line 11

def api_endpoint
  @api_endpoint
end

#tracksObject (readonly)

Returns the value of attribute tracks.



11
12
13
# File 'lib/commands/track/command.rb', line 11

def tracks
  @tracks
end

#tracks_yamlObject (readonly)

Returns the value of attribute tracks_yaml.



11
12
13
# File 'lib/commands/track/command.rb', line 11

def tracks_yaml
  @tracks_yaml
end

Instance Method Details

#listObject



30
31
32
33
34
35
# 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) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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