lib/shelly/app.rb in shelly-0.1.6 vs lib/shelly/app.rb in shelly-0.1.7
- old
+ new
@@ -2,11 +2,12 @@
require 'launchy'
require 'shelly/backup'
module Shelly
class App < Model
- DATABASE_KINDS = %w(postgresql mongodb redis none)
+ DATABASE_KINDS = %w(postgresql mongodb redis)
+ DATABASE_CHOICES = DATABASE_KINDS + %w(none)
SERVER_SIZES = %w(small large)
attr_accessor :code_name, :databases, :ruby_version, :environment,
:git_url, :domains, :web_server_ip, :mail_server_ip, :size, :thin
@@ -37,40 +38,34 @@
def remove_git_remote
system("git remote rm #{code_name} > /dev/null 2>&1")
end
- def generate_cloudfile
- @email = current_user.email
- thin = (size == "small" ? 2 : 4)
- template = File.read(cloudfile_template_path)
- cloudfile = ERB.new(template, 0, "%<>-")
- cloudfile.result(binding)
- end
-
- def cloudfile_template_path
- File.join(File.dirname(__FILE__), "templates", "Cloudfile.erb")
- end
-
def create
attributes = {:code_name => code_name}
response = shelly.create_app(attributes)
self.git_url = response["git_url"]
self.domains = response["domains"]
self.ruby_version = response["ruby_version"]
self.environment = response["environment"]
end
+ def create_cloudfile
+ cloudfile = Cloudfile.new
+ cloudfile.code_name = code_name
+ cloudfile.ruby_version = ruby_version
+ cloudfile.environment = environment
+ cloudfile.domains = domains
+ cloudfile.size = size
+ cloudfile.databases = databases
+ cloudfile.create
+ end
+
def delete
shelly.delete_app(code_name)
end
- def create_cloudfile
- content = generate_cloudfile
- File.open(cloudfile_path, "a+") { |f| f << content }
- end
-
def deploy_logs
shelly.deploy_logs(code_name)
end
def deploy_log(log)
@@ -114,18 +109,15 @@
def redeploy
shelly.redeploy(code_name)
end
- def cloudfile_path
- File.join(Dir.pwd, "Cloudfile")
- end
-
def self.guess_code_name
guessed = nil
- if Cloudfile.present?
- clouds = Cloudfile.new.clouds
+ cloudfile = Cloudfile.new
+ if cloudfile.present?
+ clouds = cloudfile.clouds
if clouds.grep(/staging/).present?
guessed = "production"
production_clouds = clouds.grep(/production/)
production_clouds.sort.each do |cloud|
cloud =~ /production(\d*)/
@@ -181,9 +173,13 @@
ssh("rake_runner \"#{task}\"")
end
def attributes
@attributes ||= shelly.app(code_name)
+ end
+
+ def statistics
+ @stats ||= shelly.statistics(code_name)
end
def web_server_ip
attributes["web_server_ip"]
end