class Shacho::Account
Public Class Methods
clear(options)
click to toggle source
# File lib/shacho/account.rb, line 55 def self.clear(options) accounts.each do |account| remove([File.basename(account)]) end end
create(options)
click to toggle source
# File lib/shacho/account.rb, line 5 def self.create(options) # TODO Throw error for incorrect params name = options.first filename = account_folder(name) if !File.exists?(filename) || !File.directory?(filename) FileUtils.mkdir_p(filename) end update_credentials(name) Key.generate(name) end
edit(options)
click to toggle source
# File lib/shacho/account.rb, line 36 def self.edit(options) # TODO Throw error for incorrect params # TODO Refactor name = options.first Runner.error account_not_found(name) if !exists?(name) update_credentials(name) end
list(options)
click to toggle source
# File lib/shacho/account.rb, line 28 def self.list(options) # TODO Throw error for incorrect params accounts.each do |account| account_name = File.basename(account) puts account_name if !(["..", "."].include?(account)) end end
remove(options)
click to toggle source
# File lib/shacho/account.rb, line 44 def self.remove(options) # TODO Throw error for incorrect params # TODO Refactor name = options.first Runner.error account_not_found(name) if !exists?(name) # TODO Account for a 'corrupted' ~/.heroku/credentials # i.e. pointing to deleted account FileUtils.rm_r account_folder(name) end
use(options)
click to toggle source
# File lib/shacho/account.rb, line 16 def self.use(options) # TODO Throw error for incorrect params # TODO Refactor name = options.first Runner.error account_not_found(name) if !exists?(name) credential_file = "#{account_folder(name)}/credentials" heroku_credentials = "#{HEROKU_PREFIX}/credentials" FileUtils.ln_sf credential_file, heroku_credentials Key.use(name) end
which(options)
click to toggle source
# File lib/shacho/account.rb, line 61 def self.which(options) puts current_credentials end
Private Class Methods
account_folder(name)
click to toggle source
# File lib/shacho/account.rb, line 70 def self.account_folder(name) return "#{HEROKU_PREFIX}/accounts/#{name}" end
account_not_found(name)
click to toggle source
# File lib/shacho/account.rb, line 84 def self.account_not_found(name) "Error: '#{name}' not found. Create account with: shacho create #{name}" end
accounts()
click to toggle source
# File lib/shacho/account.rb, line 88 def self.accounts Dir.glob "#{HEROKU_PREFIX}/accounts/*" end
current_credentials()
click to toggle source
# File lib/shacho/account.rb, line 92 def self.current_credentials current_credentials = %x[readlink "#{HEROKU_PREFIX}/credentials"] account_dir = %x[dirname "#{current_credentials}"] return File.basename(account_dir) end
exists?(name)
click to toggle source
# File lib/shacho/account.rb, line 80 def self.exists?(name) File.exists?(account_folder(name)) end
update_credentials(name)
click to toggle source
# File lib/shacho/account.rb, line 74 def self.update_credentials(name) credential = Credential.new credential.prompt(name) credential.write(account_folder(name)) end
Public Instance Methods
method_missing(sym, *args, &block)
click to toggle source
# File lib/shacho/account.rb, line 65 def method_missing(sym, *args, &block) Runner.error("Unsupported action. Run `shacho help` for more information") end