Permalink
Browse files

First commit

  • Loading branch information...
1 parent f12165c commit 5ad06ee99f0cef89ae01d6331eae7b0d367a313a @winton committed Sep 16, 2011
View
@@ -15,4 +15,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,4 +1,4 @@
-GemTemplate
+CapReserve
===========
A gem template for new projects.
@@ -16,8 +16,8 @@ Setup the template
You only have to do this once.
<pre>
-git clone git@github.com:winton/gem_template.git
-cd gem_template
+git clone git@github.com:winton/cap_reserve.git
+cd cap_reserve
stencil
</pre>
@@ -29,7 +29,7 @@ Do this for every new project.
<pre>
mkdir my_project
git init
-stencil gem_template
+stencil cap_reserve
rake rename
</pre>
View
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/lib/gem_template/gems'
+require File.dirname(__FILE__) + '/lib/cap_reserve/gems'
-GemTemplate::Gems.activate %w(rake rspec)
+CapReserve::Gems.activate %w(rake rspec)
require 'rake'
@@ -11,7 +11,7 @@ end
def gemspec
@gemspec ||= begin
- file = File.expand_path('../gem_template.gemspec', __FILE__)
+ file = File.expand_path('../cap_reserve.gemspec', __FILE__)
eval(File.read(file), binding, file)
end
end
@@ -33,9 +33,9 @@ task :gem do
root = File.expand_path('../', __FILE__)
pkg = "#{root}/pkg"
system "rm -Rf #{pkg}"
- GemTemplate::Gems.gemset_names.each do |gemset|
+ CapReserve::Gems.gemset_names.each do |gemset|
ENV['GEMSET'] = gemset.to_s
- system "cd #{root} && gem build gem_template.gemspec"
+ system "cd #{root} && gem build cap_reserve.gemspec"
system "mkdir -p #{pkg} && mv *.gem pkg"
end
ENV['GEMSET'] = old_gemset
@@ -67,17 +67,17 @@ namespace :gems do
gemset = ENV['GEMSET']
sudo = ENV['SUDO'] == '1' ? 'sudo' : ''
- GemTemplate::Gems.gemset = gemset if gemset
+ CapReserve::Gems.gemset = gemset if gemset
if dev
- gems = GemTemplate::Gems.gemspec.development_dependencies
+ gems = CapReserve::Gems.gemspec.development_dependencies
else
- gems = GemTemplate::Gems.gemspec.dependencies
+ gems = CapReserve::Gems.gemspec.dependencies
end
gems.each do |name|
name = name.to_s
- version = GemTemplate::Gems.versions[name.to_sym]
+ version = CapReserve::Gems.versions[name.to_sym]
if Gem.source_index.find_name(name, version).empty?
version = version ? "-v #{version}" : ''
system "#{sudo} gem install #{name} #{version} #{docs}"
@@ -91,30 +91,4 @@ end
desc "Validate the gemspec"
task :gemspec do
gemspec.validate
-end
-
-# DELETE AFTER USING
-desc "Rename project"
-task :rename do
- name = ENV['NAME'] || File.basename(Dir.pwd)
- camelize = lambda do |str|
- str.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
- end
- dir = Dir['**/gem_template*']
- begin
- from = dir.pop
- if from
- to = from.split('/')
- to[-1].gsub!('gem_template', name)
- FileUtils.mv(from, to.join('/'))
- end
- end while dir.length > 0
- Dir["**/*"].each do |path|
- if File.file?(path)
- `sed -i '' 's/gem_template/#{name}/g' #{path}`
- `sed -i '' 's/GemTemplate/#{camelize.call(name)}/g' #{path}`
- no_space = File.read(path).gsub(/\s+\z/, '')
- File.open(path, 'w') { |f| f.write(no_space) }
- end
- end
end
View
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + "/../lib/cap_reserve")
View
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + "/../lib/gem_template")
@@ -3,26 +3,26 @@ root = File.expand_path('../', __FILE__)
lib = "#{root}/lib"
$:.unshift lib unless $:.include?(lib)
-require 'gem_template/gems'
-GemTemplate::Gems.gemset ||= ENV['GEMSET'] || :default
+require 'cap_reserve/gems'
+CapReserve::Gems.gemset ||= ENV['GEMSET'] || :default
Gem::Specification.new do |s|
- GemTemplate::Gems.gemspec.hash.each do |key, value|
- if key == 'name' && GemTemplate::Gems.gemset != :default
- s.name = "#{value}-#{GemTemplate::Gems.gemset}"
- elsif key == 'summary' && GemTemplate::Gems.gemset == :solo
+ CapReserve::Gems.gemspec.hash.each do |key, value|
+ if key == 'name' && CapReserve::Gems.gemset != :default
+ s.name = "#{value}-#{CapReserve::Gems.gemset}"
+ elsif key == 'summary' && CapReserve::Gems.gemset == :solo
s.summary = value + " (no dependencies)"
elsif !%w(dependencies development_dependencies).include?(key)
s.send "#{key}=", value
end
end
- GemTemplate::Gems.dependencies.each do |g|
- s.add_dependency g.to_s, GemTemplate::Gems.versions[g]
+ CapReserve::Gems.dependencies.each do |g|
+ s.add_dependency g.to_s, CapReserve::Gems.versions[g]
end
- GemTemplate::Gems.development_dependencies.each do |g|
- s.add_development_dependency g.to_s, GemTemplate::Gems.versions[g]
+ CapReserve::Gems.development_dependencies.each do |g|
+ s.add_development_dependency g.to_s, CapReserve::Gems.versions[g]
end
s.executables = `cd #{root} && git ls-files bin/*`.split("\n").collect { |f| File.basename(f) }
View
@@ -1,6 +0,0 @@
-development:
- adapter: mysql
- database: gem_template
- username: root
- password:
- host: localhost
View
@@ -1,3 +1,5 @@
-gem_template:
+cap_reserve:
rake: >=0.8.7
- rspec: ~>1.0
+ rspec: ~>1.0
+ default:
+ nestful: =0.0.7
View
@@ -1,13 +1,13 @@
-name: gem_template
+name: cap_reserve
version: 0.1.0
authors:
- -
-email:
-homepage:
+ - Winton Welsh
+email: mail@wintoni.us
+homepage: https://github.com/winton/cap_reserve
summary:
description:
dependencies:
- -
+ - nestful
development_dependencies:
- rake
- rspec
View
@@ -0,0 +1,47 @@
+require File.dirname(__FILE__) + '/cap_reserve/gems'
+
+CapReserve::Gems.activate %w(nestful)
+require 'nestful'
+
+$:.unshift File.dirname(__FILE__)
+
+Capistrano::Configuration.instance(:must_exist).load do
+
+ desc "Reserve environment using RESERVE=minutes"
+ task :reserve do
+ env, user, time, force, url =
+ ENV['RESERVE_ENV'], ENV['USER'], ENV['RESERVE'], ENV['FORCE'], ENV['RESERVE_URL']
+
+ create = lambda do |params|
+ if time
+ Nestful.get("#{url}/reservations/create", :format => :json, :params => {
+ :environment => env, :user => user, :seconds => time.to_i * 60
+ }.merge(params))
+ puts "Reservation created: #{user}@#{env} for #{time.to_i} minutes"
+ elsif force
+ res = Nestful.get("#{url}/reservations/destroy", :params => { :environment => env }, :format => :json)
+ if res['status'] == 'reserved'
+ puts "Reservation destroyed: #{res['user']}@#{env} (#{(Time.at(res['expires']) - Time.now) / 60} minutes left)"
+ end
+ end
+ end
+
+ if env && user
+ if force
+ create.call(:force => true)
+ else
+ res = Nestful.get("#{url}/reservations/show", :params => { :environment => env }, :format => :json)
+ if res['status'] == 'reserved'
+ if res['user'] == user
+ create.call({})
+ else
+ puts "Reservation exists: #{res['user']}@#{env} for #{(Time.at(res['expires']) - Time.now) / 60} minutes"
+ exit 0
+ end
+ else
+ create.call({})
+ end
+ end
+ end
+ end
+end
@@ -1,8 +1,8 @@
-unless defined?(GemTemplate::Gems)
+unless defined?(CapReserve::Gems)
require 'yaml'
- module GemTemplate
+ module CapReserve
module Gems
class <<self
View
@@ -1,8 +0,0 @@
-require File.dirname(__FILE__) + '/gem_template/gems'
-
-GemTemplate::Gems.activate %w()
-
-$:.unshift File.dirname(__FILE__)
-
-module GemTemplate
-end
View
@@ -1 +1 @@
-require File.expand_path(File.dirname(__FILE__) + '/../lib/gem_template')
+require File.expand_path(File.dirname(__FILE__) + '/../lib/cap_reserve')
Oops, something went wrong.

0 comments on commit 5ad06ee

Please sign in to comment.