Class: Config
- Inherits:
-
Object
- Object
- Config
- Defined in:
- lib/notify_twitch/config.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/notify_twitch/config.rb', line 5 def initialize if File.file? "#{ENV['HOME']}/.config/notify-twitch/config.json" config = JSON.parse File.read("#{ENV['HOME']}/.config/notify-twitch/config.json") @client_id = config["client-id"] @username = config["username"] else puts "Can't find your config :(. Don't Worry I'll make you a new one!" puts "Enter your client-id. Can be found at your twitch apps dashboard" @client_id = gets.chomp puts "Enter your usename" @username = gets.chomp FileUtils.mkdir_p "#{ENV['HOME']}/.config/notify-twitch" unless File.exists? "#{ENV['HOME']}/.config/notify-twitch" File.open("#{ENV['HOME']}/.config/notify-twitch/config.json","w") do |f| f << JSON.pretty_generate({"client-id" => @client_id,"username" => @username}) end end end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
4 5 6 |
# File 'lib/notify_twitch/config.rb', line 4 def client_id @client_id end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
4 5 6 |
# File 'lib/notify_twitch/config.rb', line 4 def username @username end |