Skip to content

Instantly share code, notes, and snippets.

@Atalanta
Created April 3, 2011 03:58
Show Gist options
  • Save Atalanta/900163 to your computer and use it in GitHub Desktop.
Save Atalanta/900163 to your computer and use it in GitHub Desktop.
class Magick < Sinatra::Base
helpers do
def smash(version, environment)
environments = get_environments
versions = environments[environment]
index = versions.index(version)
environments[environment].delete_at(index)
File.open("environments.yaml", "w") { |file| file.write(environments.to_yaml) }
end
def get_environments
key = "sekrit"
secret = "reallysekrit"
@vapour = Vapour.new(key, secret)
stacks = @vapour.describe_stacks
File.open("environments.yaml") { |file| YAML.load(file) }
end
def get_index
# index = File.open("index.yaml") { |file| YAML.load(file) }
@vapour = Vapour.new(key, secret)
@vapour.describe_stacks.map{|stack| stack.description }.uniq
end
def promote(version, environment)
environments = get_environments
environment_index = get_index
current_environment_index = environment_index.index(environment).to_i
if (current_environment_index + 1) == environment.size
return ap "There's no environment more advanced than #{environment}"
end
next_environment = environment_index[current_environment_index + 1]
environments[next_environment] << version
File.open("environments.yaml", "w") { |file| file.write(environments.to_yaml) }
end
end
get "/" do
@environments = get_environments
haml :index
end
post "/" do
smash(params[:version], params[:environment])
redirect "/"
end
post "/promote" do
promote(params[:version], params[:environment])
redirect "/"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment