Class: Pagoda::Command::App

Inherits:
Base show all
Defined in:
lib/pagoda/cli/helpers/app.rb

Constant Summary

Constants included from Helpers

Helpers::INDENT

Instance Attribute Summary

Attributes inherited from Base

#args, #client, #globals, #options

Instance Method Summary collapse

Methods inherited from Base

#app, ask_for_credentials, #branch, #commit, #extract_app_from_git_config, #extract_app_from_remote, #extract_git_clone_url, #find_branch, #find_commit, #git_remotes, #home_dir, #initialize, #locate_app_root, #loop_transaction, #password, #remote, #shell, #user

Methods included from Helpers

#build_indent, #confirm, #create_git_remote, #display, #display_name, #error, #format_date, #git, #has_git?, #home_directory, #remove_app, #remove_git_remote, #running_on_a_mac?, #running_on_windows?

Constructor Details

This class inherits a constructor from Pagoda::Command::Base

Instance Method Details

#cloneObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pagoda/cli/helpers/app.rb', line 61

def clone
  my_app = args.first || app
  id = client.app_info(my_app)[:id]
  display
  git "clone [email protected]:#{id}.git #{my_app}"
  Dir.chdir(my_app)
  git "config --add pagoda.id #{id}"
  Dir.chdir("..")
  display
  display "+ Repo has been added. Navigate to folder #{my_app}."
rescue
  error "We were not able to access that app"
end

#createObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/pagoda/cli/helpers/app.rb', line 75

def create
  name = args.first || app
  if client.app_available?(name)
    id = client.app_create(name)[:id]
    display("Creating #{name}...", false)
    loop_transaction(name)
    d_remote = create_git_remote(id, remote)
    display "#{name} created"
    display "----------------------------------------------------"
    display
    display "LIVE URL    : http://#{name}.pagodabox.com"
    display "ADMIN PANEL : http://dashboard.pagodabox.com/apps/#{name}"
    display
    display "----------------------------------------------------"
    display
    display "+ Use 'git push #{d_remote} --all' to push your code live"
  else
    error "App name (#{name}) is already taken"
  end
end

#deployObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/pagoda/cli/helpers/app.rb', line 96

def deploy
  display
  my_app = app
  if client.app_info(my_app)[:active_transaction_id] == nil
    begin
      client.app_deploy(my_app, branch, commit)
    rescue RestClient::Found => e
      # do nothing because we found it HURRAY!
    end
    display "+ deploying current branch and commit...", true
    loop_transaction
  else
    error "Your app is currently in transaction, Please try again later."          
  end
end

#destroyObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/pagoda/cli/helpers/app.rb', line 120

def destroy
  display
  my_app = app
  dname = display_name(my_app) # Make the app name look better
  if options[:force]
    display "+ Destroying #{dname}"
    client.app_destroy(my_app)
    display "+ #{dname} has been successfully destroyed. RIP #{dname}."
    remove_app(my_app)
  else
    if confirm ["Are you totally completely sure you want to delete #{dname} forever and ever?", "THIS CANNOT BE UNDONE! "]
      display
      display "+ Destroying #{dname}"
      client.app_destroy(my_app)
      display "+ #{dname} has been successfully destroyed. RIP #{dname}."
      remove_app(my_app)
    end
  end
  display
end

#infoObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pagoda/cli/helpers/app.rb', line 22

def info
  display
  info = client.app_info(app)
  error("What application are you looking for?") unless info.is_a?(Hash)
  display "INFO - #{info[:name]}"
  display "//////////////////////////////////"
  display "name        :  #{info[:name]}"
  display "clone url   :  [email protected]:#{info[:id]}.git"
  display
  display "owner"
  display "   username :  #{info[:owner][:username]}"
  display "   email    :  #{info[:owner][:email]}"
  display
  display "collaborators"
  info[:collaborators].each do |collab|
  display "   username :  #{collab[:username]}"
  display "   email    :  #{collab[:email]}"
  end
  display
  display "ssh_portal  :  #{info[:ssh] ? 'enabled' : 'disabled'}"
  display
end

#initObject



56
57
58
59
# File 'lib/pagoda/cli/helpers/app.rb', line 56

def init
  id = client.app_info(args.first || app)[:id] rescue error("We could not find the application you were looking for")
  create_git_remote(id, remote)
end

#listObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pagoda/cli/helpers/app.rb', line 6

def list
  apps = client.app_list
  unless apps.empty?
    display
    display "APPS"
    display "//////////////////////////////////"
    display
    apps.each do |app|
      display "- #{app[:name]}"
    end
  else
    error ["looks like you haven't launched any apps", "type 'pagoda create' to create this project on pagodabox"]
  end
  display
end

#renameObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/pagoda/cli/helpers/app.rb', line 45

def rename
  old_name = options[:old] || app
  new_name = options[:new] || args.first
  error "I need the new name" unless new_name
  error "New name and existiong name cannot be the same" if new_name == old_name
  client.app_update(old_name, {:name => new_name})
  display "Successfully changed name to #{new_name}"
rescue
  error "Given name was either invalid or already in use"
end

#rollbackObject



112
113
114
115
116
117
118
# File 'lib/pagoda/cli/helpers/app.rb', line 112

def rollback
  display
  client.app_rollback(app)
  display "+ undo..."
  loop_transaction
  display
end