Class: Shacho::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/shacho/account.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



65
66
67
# File 'lib/shacho/account.rb', line 65

def method_missing(sym, *args, &block)
  Runner.error("Unsupported action.  Run `shacho help` for more information")
end

Class Method Details

.clear(options) ⇒ Object



55
56
57
58
59
# File 'lib/shacho/account.rb', line 55

def self.clear(options)
  accounts.each do ||
    remove([File.basename()])
  end
end

.create(options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/shacho/account.rb', line 5

def self.create(options)
  # TODO Throw error for incorrect params
  name = options.first
  filename = (name)
  if !File.exists?(filename) || !File.directory?(filename)
    FileUtils.mkdir_p(filename)
  end
  update_credentials(name)
  Key.generate(name)
end

.edit(options) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/shacho/account.rb', line 36

def self.edit(options)
  # TODO Throw error for incorrect params
  # TODO Refactor
  name = options.first
  Runner.error (name) if !exists?(name)
  update_credentials(name)
end

.list(options) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/shacho/account.rb', line 28

def self.list(options)
  # TODO Throw error for incorrect params
  accounts.each do ||
     = File.basename()
    puts  if !(["..", "."].include?())
  end
end

.remove(options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/shacho/account.rb', line 44

def self.remove(options)
  # TODO Throw error for incorrect params
  # TODO Refactor
  name = options.first
  Runner.error (name) if !exists?(name)

  # TODO Account for a 'corrupted' ~/.heroku/credentials
  #  i.e. pointing to deleted account
  FileUtils.rm_r (name)
end

.use(options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/shacho/account.rb', line 16

def self.use(options)
  # TODO Throw error for incorrect params
  # TODO Refactor
  name = options.first
  Runner.error (name) if !exists?(name)

  credential_file = "#{(name)}/credentials"
  heroku_credentials = "#{HEROKU_PREFIX}/credentials"
  FileUtils.ln_sf credential_file, heroku_credentials
  Key.use(name)
end

.which(options) ⇒ Object



61
62
63
# File 'lib/shacho/account.rb', line 61

def self.which(options)
  puts current_credentials
end