Class: Stars::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/stars/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
# File 'lib/stars/config.rb', line 8

def initialize
  @keep = Keep.new(config_path)
end

Instance Attribute Details

#keepObject

Returns the value of attribute keep.



4
5
6
# File 'lib/stars/config.rb', line 4

def keep
  @keep
end

Instance Method Details

#config_pathObject



12
13
14
# File 'lib/stars/config.rb', line 12

def config_path
  "#{File.expand_path('~')}/.stars.yml"
end

#prompt_for_serviceObject



20
21
22
23
24
25
# File 'lib/stars/config.rb', line 20

def prompt_for_service
  puts "What service do you want to track?"
  puts "Your options: #{Stars.uninstalled_services.join(', ')}"
  service = $stdin.gets.chomp.downcase
  prompt_for_username(service)
end

#prompt_for_username(service) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/stars/config.rb', line 27

def prompt_for_username(service)
  return @keep.get(service) if @keep.present?(service)

  if !Stars.uninstalled_services.empty? and !Stars.uninstalled_services.include?(service.downcase)
    puts("You need to pick something from: #{Stars.uninstalled_services.join(', ')}")
    return exit
  end

  puts "What's your username for #{service}?"
  username = $stdin.gets.chomp
  @keep.set(service,username)
end

#username(service) ⇒ Object



16
17
18
# File 'lib/stars/config.rb', line 16

def username(service)
  prompt_for_username(service)
end