Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'rails' of github.com:winton/gem_template

Conflicts:
	Rakefile
	bin/gem_template
	cap_reserve.gemspec
	config/gemsets.yml
	config/gemspec.yml
	lib/cap_reserve/gems.rb
	lib/gem_template.rb
	rails/init.rb
	spec/cap_reserve/gems_spec.rb
	spec/spec_helper.rb
  • Loading branch information...
commit 67c8bc399c47fb6f2fc7df1f0bc8dcc8d7396b64 2 parents 161eab5 + 8e9b60b
Winton Welsh authored
3  .gitignore
View
@@ -1,5 +1,6 @@
.DS_Store
*.gem
-coverage
+.bundle
+Gemfile.lock
pkg
tmp
3  Gemfile
View
@@ -0,0 +1,3 @@
+source "http://rubygems.org"
+
+gemspec
95 Rakefile
View
@@ -1,94 +1 @@
-require File.dirname(__FILE__) + '/lib/cap_reserve/gems'
-
-CapReserve::Gems.activate %w(rake rspec)
-
-require 'rake'
-
-begin
- require 'spec/rake/spectask'
-rescue Exception => e
-end
-
-def gemspec
- @gemspec ||= begin
- file = File.expand_path('../cap_reserve.gemspec', __FILE__)
- eval(File.read(file), binding, file)
- end
-end
-
-if defined?(Spec::Rake::SpecTask)
- desc "Run specs"
- Spec::Rake::SpecTask.new do |t|
- t.spec_files = FileList['spec/**/*_spec.rb']
- t.spec_opts = %w(-fs --color)
- t.warning = true
- end
- task :spec
- task :default => :spec
-end
-
-desc "Build gem(s)"
-task :gem do
- old_gemset = ENV['GEMSET']
- root = File.expand_path('../', __FILE__)
- pkg = "#{root}/pkg"
- system "rm -Rf #{pkg}"
- CapReserve::Gems.gemset_names.each do |gemset|
- ENV['GEMSET'] = gemset.to_s
- system "cd #{root} && gem build cap_reserve.gemspec"
- system "mkdir -p #{pkg} && mv *.gem pkg"
- end
- ENV['GEMSET'] = old_gemset
-end
-
-namespace :gem do
- desc "Install gem(s)"
- task :install do
- Rake::Task['gem'].invoke
- Dir["#{File.dirname(__FILE__)}/pkg/*.gem"].each do |pkg|
- system "gem install #{pkg} --no-ri --no-rdoc"
- end
- end
-
- desc "Push gem(s)"
- task :push do
- Rake::Task['gem'].invoke
- Dir["#{File.dirname(__FILE__)}/pkg/*.gem"].each do |pkg|
- system "gem push #{pkg}"
- end
- end
-end
-
-namespace :gems do
- desc "Install gem dependencies (DEV=0 DOCS=0 GEMSPEC=default SUDO=0)"
- task :install do
- dev = ENV['DEV'] == '1'
- docs = ENV['DOCS'] == '1' ? '' : '--no-ri --no-rdoc'
- gemset = ENV['GEMSET']
- sudo = ENV['SUDO'] == '1' ? 'sudo' : ''
-
- CapReserve::Gems.gemset = gemset if gemset
-
- if dev
- gems = CapReserve::Gems.gemspec.development_dependencies
- else
- gems = CapReserve::Gems.gemspec.dependencies
- end
-
- gems.each do |name|
- name = name.to_s
- 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}"
- else
- puts "already installed: #{name} #{version}"
- end
- end
- end
-end
-
-desc "Validate the gemspec"
-task :gemspec do
- gemspec.validate
-end
+require 'bundler/gem_tasks'
33 cap_reserve.gemspec
View
@@ -1,32 +1,25 @@
# -*- encoding: utf-8 -*-
root = File.expand_path('../', __FILE__)
lib = "#{root}/lib"
+
$:.unshift lib unless $:.include?(lib)
-
-require 'cap_reserve/gems'
-CapReserve::Gems.gemset ||= ENV['GEMSET'] || :default
Gem::Specification.new do |s|
- 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
-
- CapReserve::Gems.dependencies.each do |g|
- s.add_dependency g.to_s, CapReserve::Gems.versions[g]
- end
-
- CapReserve::Gems.development_dependencies.each do |g|
- s.add_development_dependency g.to_s, CapReserve::Gems.versions[g]
- end
+ s.name = "cap_reserve"
+ s.version = '0.1.0'
+ s.platform = Gem::Platform::RUBY
+ s.authors = [ "Winton Welsh" ]
+ s.email = [ "mail@wintoni.us" ]
+ s.homepage = "http://guthub.com/winton/cap_reserve"
+ s.summary = %q{Uses a maitre_d server to reserve time on deploy environments}
+ s.description = %q{Uses a maitre_d server to reserve time on deploy environments.}
s.executables = `cd #{root} && git ls-files bin/*`.split("\n").collect { |f| File.basename(f) }
s.files = `cd #{root} && git ls-files`.split("\n")
s.require_paths = %w(lib)
s.test_files = `cd #{root} && git ls-files -- {features,test,spec}/*`.split("\n")
+
+ s.add_development_dependency "rspec", "~> 1.0"
+
+ s.add_dependency "nestful", "= 0.0.7"
end
5 config/gemsets.yml
View
@@ -1,5 +0,0 @@
-cap_reserve:
- rake: >=0.8.7
- rspec: ~>1.0
- default:
- nestful: =0.0.7
13 config/gemspec.yml
View
@@ -1,13 +0,0 @@
-name: cap_reserve
-version: 0.1.0
-authors:
- - Winton Welsh
-email: mail@wintoni.us
-homepage: https://github.com/winton/cap_reserve
-summary:
-description:
-dependencies:
- - nestful
-development_dependencies:
- - rake
- - rspec
6 lib/cap_reserve.rb
View
@@ -1,7 +1,5 @@
-require File.dirname(__FILE__) + '/cap_reserve/gems'
-
-CapReserve::Gems.activate %w(nestful)
-require 'nestful'
+gem "nestful", "= 0.0.7"
+require "nestful"
$:.unshift File.dirname(__FILE__)
159 lib/cap_reserve/gems.rb
View
@@ -1,159 +0,0 @@
-unless defined?(CapReserve::Gems)
-
- require 'yaml'
-
- module CapReserve
- module Gems
- class <<self
-
- attr_accessor :config
- attr_reader :gemset, :gemsets, :versions
-
- class SimpleStruct
- attr_reader :hash
-
- def initialize(hash)
- @hash = hash
- @hash.each do |key, value|
- self.class.send(:define_method, key) { @hash[key] }
- self.class.send(:define_method, "#{key}=") { |v| @hash[key] = v }
- end
- end
- end
-
- Gems.config = SimpleStruct.new(
- :gemsets => [ "#{File.expand_path('../../../', __FILE__)}/config/gemsets.yml" ],
- :gemspec => "#{File.expand_path('../../../', __FILE__)}/config/gemspec.yml",
- :warn => true
- )
-
- def activate(*gems)
- begin
- require 'rubygems' unless defined?(::Gem)
- rescue LoadError
- puts "rubygems library could not be required" if @config.warn
- end
-
- self.gemset ||= gemset_from_loaded_specs
-
- gems.flatten.collect { |g| g.to_sym }.each do |name|
- version = @versions[name]
- vendor = File.expand_path("../../../vendor/#{name}/lib", __FILE__)
- warning = "#{name} #{"(#{version})" if version} failed to activate"
- if File.exists?(vendor)
- $:.unshift vendor
- elsif defined?(gem)
- begin
- gem name.to_s, version
- rescue Exception => e
- puts warning if @config.warn
- end
- else
- puts warning if @config.warn
- end
- end
- end
-
- def dependencies
- dependency_filter(@gemspec.dependencies, @gemset)
- end
-
- def development_dependencies
- dependency_filter(@gemspec.development_dependencies, @gemset)
- end
-
- def gemset=(gemset)
- if gemset
- @gemset = gemset.to_sym
-
- @gemsets = @config.gemsets.reverse.collect { |config|
- if config.is_a?(::String)
- YAML::load(File.read(config)) rescue {}
- elsif config.is_a?(::Hash)
- config
- end
- }.inject({}) do |hash, config|
- deep_merge(hash, symbolize_keys(config))
- end
-
- @versions = (@gemsets[gemspec.name.to_sym] || {}).inject({}) do |hash, (key, value)|
- if !value.is_a?(::Hash) && value
- hash[key] = value
- elsif key == @gemset
- (value || {}).each { |k, v| hash[k] = v }
- end
- hash
- end
- else
- @gemset = nil
- @gemsets = nil
- @versions = nil
- end
- end
-
- def gemset_names
- (
- [ :default ] +
- @gemsets[gemspec.name.to_sym].inject([]) { |array, (key, value)|
- array.push(key) if value.is_a?(::Hash) || value.nil?
- array
- }
- ).uniq
- end
-
- def gemspec(reload=false)
- if @gemspec && !reload
- @gemspec
- else
- data = YAML::load(File.read(@config.gemspec)) rescue {}
- @gemspec = SimpleStruct.new(data)
- end
- end
-
- private
-
- def deep_merge(first, second)
- merger = lambda do |key, v1, v2|
- Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
- end
- first.merge(second, &merger)
- end
-
- def dependency_filter(dependencies, match)
- (dependencies || []).inject([]) { |array, value|
- if value.is_a?(::Hash)
- array += value[match.to_s] if value[match.to_s]
- else
- array << value
- end
- array
- }.uniq.collect(&:to_sym)
- end
-
- def gemset_from_loaded_specs
- if defined?(Gem)
- Gem.loaded_specs.each do |name, spec|
- if name == gemspec.name
- return :default
- elsif name[0..gemspec.name.length] == "#{gemspec.name}-"
- return name[gemspec.name.length+1..-1].to_sym
- end
- end
- :default
- else
- :none
- end
- end
-
- def symbolize_keys(hash)
- return {} unless hash.is_a?(::Hash)
- hash.inject({}) do |options, (key, value)|
- value = symbolize_keys(value) if value.is_a?(::Hash)
- options[(key.to_sym rescue key) || key] = value
- options
- end
- end
- end
- end
- end
-end
249 spec/cap_reserve/gems_spec.rb
View
@@ -1,249 +0,0 @@
-require 'spec_helper'
-
-describe CapReserve::Gems do
-
- before(:each) do
- @old_config = CapReserve::Gems.config
-
- CapReserve::Gems.config.gemspec = "#{$root}/spec/fixtures/gemspec.yml"
- CapReserve::Gems.config.gemsets = [
- "#{$root}/spec/fixtures/gemsets.yml"
- ]
- CapReserve::Gems.config.warn = true
-
- CapReserve::Gems.gemspec true
- CapReserve::Gems.gemset = nil
- end
-
- after(:each) do
- CapReserve::Gems.config = @old_config
- end
-
- describe :activate do
- it "should activate gems" do
- CapReserve::Gems.stub!(:gem)
- CapReserve::Gems.should_receive(:gem).with('rspec', '=1.3.1')
- CapReserve::Gems.should_receive(:gem).with('rake', '=0.8.7')
- CapReserve::Gems.activate :rspec, 'rake'
- end
- end
-
- describe :gemset= do
- before(:each) do
- CapReserve::Gems.config.gemsets = [
- {
- :name => {
- :rake => '>0.8.6',
- :default => {
- :externals => '=1.0.2'
- }
- }
- },
- "#{$root}/spec/fixtures/gemsets.yml"
- ]
- end
-
- describe :default do
- before(:each) do
- CapReserve::Gems.gemset = :default
- end
-
- it "should set @gemset" do
- CapReserve::Gems.gemset.should == :default
- end
-
- it "should set @gemsets" do
- CapReserve::Gems.gemsets.should == {
- :name => {
- :rake => ">0.8.6",
- :default => {
- :externals => '=1.0.2',
- :mysql => "=2.8.1",
- :rspec => "=1.3.1"
- },
- :rspec2 => {
- :mysql2 => "=0.2.6",
- :rspec => "=2.3.0"
- },
- :solo => nil
- }
- }
- end
-
- it "should set Gems.versions" do
- CapReserve::Gems.versions.should == {
- :externals => "=1.0.2",
- :mysql => "=2.8.1",
- :rake => ">0.8.6",
- :rspec => "=1.3.1"
- }
- end
-
- it "should return proper values for Gems.dependencies" do
- CapReserve::Gems.dependencies.should == [ :rake, :mysql ]
- CapReserve::Gems.development_dependencies.should == []
- end
-
- it "should return proper values for Gems.gemset_names" do
- CapReserve::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
- end
- end
-
- describe :rspec2 do
- before(:each) do
- CapReserve::Gems.gemset = "rspec2"
- end
-
- it "should set @gemset" do
- CapReserve::Gems.gemset.should == :rspec2
- end
-
- it "should set @gemsets" do
- CapReserve::Gems.gemsets.should == {
- :name => {
- :rake => ">0.8.6",
- :default => {
- :externals => '=1.0.2',
- :mysql => "=2.8.1",
- :rspec => "=1.3.1"
- },
- :rspec2 => {
- :mysql2=>"=0.2.6",
- :rspec => "=2.3.0"
- },
- :solo => nil
- }
- }
- end
-
- it "should set Gems.versions" do
- CapReserve::Gems.versions.should == {
- :mysql2 => "=0.2.6",
- :rake => ">0.8.6",
- :rspec => "=2.3.0"
- }
- end
-
- it "should return proper values for Gems.dependencies" do
- CapReserve::Gems.dependencies.should == [ :rake, :mysql2 ]
- CapReserve::Gems.development_dependencies.should == []
- end
-
- it "should return proper values for Gems.gemset_names" do
- CapReserve::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
- end
- end
-
- describe :solo do
- before(:each) do
- CapReserve::Gems.gemset = :solo
- end
-
- it "should set @gemset" do
- CapReserve::Gems.gemset.should == :solo
- end
-
- it "should set @gemsets" do
- CapReserve::Gems.gemsets.should == {
- :name => {
- :rake => ">0.8.6",
- :default => {
- :externals => '=1.0.2',
- :mysql => "=2.8.1",
- :rspec => "=1.3.1"
- },
- :rspec2 => {
- :mysql2=>"=0.2.6",
- :rspec => "=2.3.0"
- },
- :solo => nil
- }
- }
- end
-
- it "should set Gems.versions" do
- CapReserve::Gems.versions.should == {:rake=>">0.8.6"}
- end
-
- it "should return proper values for Gems.dependencies" do
- CapReserve::Gems.dependencies.should == [:rake]
- CapReserve::Gems.development_dependencies.should == []
- end
-
- it "should return proper values for Gems.gemset_names" do
- CapReserve::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
- end
- end
-
- describe :nil do
- before(:each) do
- CapReserve::Gems.gemset = nil
- end
-
- it "should set everything to nil" do
- CapReserve::Gems.gemset.should == nil
- CapReserve::Gems.gemsets.should == nil
- CapReserve::Gems.versions.should == nil
- end
- end
- end
-
- describe :gemset_from_loaded_specs do
- before(:each) do
- Gem.stub!(:loaded_specs)
- end
-
- it "should return the correct gemset for name gem" do
- Gem.should_receive(:loaded_specs).and_return({ "name" => nil })
- CapReserve::Gems.send(:gemset_from_loaded_specs).should == :default
- end
-
- it "should return the correct gemset for name-rspec gem" do
- Gem.should_receive(:loaded_specs).and_return({ "name-rspec2" => nil })
- CapReserve::Gems.send(:gemset_from_loaded_specs).should == :rspec2
- end
- end
-
- describe :reload_gemspec do
- it "should populate @gemspec" do
- CapReserve::Gems.gemspec.hash.should == {
- "name" => "name",
- "version" => "0.1.0",
- "authors" => ["Author"],
- "email" => "email@email.com",
- "homepage" => "http://github.com/author/name",
- "summary" => "Summary",
- "description" => "Description",
- "dependencies" => [
- "rake",
- { "default" => [ "mysql" ] },
- { "rspec2" => [ "mysql2" ] }
- ],
- "development_dependencies" => nil
- }
- end
-
- it "should create methods from keys of @gemspec" do
- CapReserve::Gems.gemspec.name.should == "name"
- CapReserve::Gems.gemspec.version.should == "0.1.0"
- CapReserve::Gems.gemspec.authors.should == ["Author"]
- CapReserve::Gems.gemspec.email.should == "email@email.com"
- CapReserve::Gems.gemspec.homepage.should == "http://github.com/author/name"
- CapReserve::Gems.gemspec.summary.should == "Summary"
- CapReserve::Gems.gemspec.description.should == "Description"
- CapReserve::Gems.gemspec.dependencies.should == [
- "rake",
- { "default" => ["mysql"] },
- { "rspec2" => [ "mysql2" ] }
- ]
- CapReserve::Gems.gemspec.development_dependencies.should == nil
- end
-
- it "should produce a valid gemspec" do
- CapReserve::Gems.gemset = :default
- gemspec = File.expand_path("../../../cap_reserve.gemspec", __FILE__)
- gemspec = eval(File.read(gemspec), binding, gemspec)
- gemspec.validate.should == true
- end
- end
-end
9 spec/fixtures/gemsets.yml
View
@@ -1,9 +0,0 @@
-name:
- rake: =0.8.7
- default:
- mysql: =2.8.1
- rspec: =1.3.1
- rspec2:
- mysql2: =0.2.6
- rspec: =2.3.0
- solo: null
15 spec/fixtures/gemspec.yml
View
@@ -1,15 +0,0 @@
-name: name
-version: 0.1.0
-authors:
- - Author
-email: email@email.com
-homepage: http://github.com/author/name
-summary: Summary
-description: Description
-dependencies:
- - rake
- - default:
- - mysql
- - rspec2:
- - mysql2
-development_dependencies: null
13 spec/spec_helper.rb
View
@@ -1,11 +1,8 @@
-require 'pp'
+require "pp"
+require "bundler"
-$root = File.expand_path('../../', __FILE__)
-require "#{$root}/lib/cap_reserve/gems"
-
-CapReserve::Gems.activate :rspec
+Bundler.require(:development)
-require "#{$root}/lib/cap_reserve"
+$root = File.expand_path('../../', __FILE__)
-Spec::Runner.configure do |config|
-end
+require "#{$root}/lib/cap_reserve"
Please sign in to comment.
Something went wrong with that request. Please try again.