Commits

Richo Healey committed daeb8db

Don't proxy to config any more, access subHash

  • Participants
  • Parent commits eb2d483

Comments (0)

Files changed (4)

       rescue NoSuchAccount
         puts "No such account"
         opts.usage
+      rescue NoDefaultAccount
+        puts "No default account configured."
+        puts "Which is unfortunate, as setting one is not implemented yet"
       rescue NoMethodError
         puts "No such command"
         opts.usage

lib/twat/actions.rb

       pin = gets.chomp
       begin
         access_token = token_request.get_access_token(oauth_verifier: pin)
-        config[opts[:account]] = {
+        config.accounts[opts[:account]] = {
           oauth_token: access_token.token,
           oauth_token_secret: access_token.secret
         }
     end
 
     def delete
-      if config.delete(opts[:account])
+      if config.accounts.delete(opts[:account])
         config.save!
         puts "Successfully deleted"
       else

lib/twat/config.rb

       self[meth]
     end
 
-    def [](key)
-      raise NoSuchAccount unless config.include?(key)
-      config[key]
-    end
-
-    def []=(key, value)
-      config[key] = value
-    end
-
-    def delete(key)
-      config.delete(key)
-    end
-
     def accounts
       return config[:accounts]
     end
 
     def default_account
+      raise NoDefaultAccount unless config.include?(:default)
+      raise NoSuchAccount unless config[:accounts].include(config[:default])
       return config[:accounts][config[:default]]
     end
 

lib/twat/exceptions.rb

 module Twat
   class NoSuchAccount < Exception; end
+  class NoDefaultAccount < Exception; end
   class NoConfigFile < Exception; end
   class Usage < Exception; end
   class InvalidCredentials < Exception; end