Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' into rails

  • Loading branch information...
commit e908b55002a3ccc8a346b72b09ab26e6460f6d64 2 parents f12165c + 7e8a9b6
@winton authored
View
1  .gitignore
@@ -1,5 +1,4 @@
.DS_Store
*.gem
-coverage
pkg
tmp
View
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+gem 'rake', '>=0.8.7', :group => :rakefile
+gem 'rspec', '~>1.0', :group => [ :rakefile, :spec ]
View
12 Gemfile.lock
@@ -0,0 +1,12 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ rake (0.9.2)
+ rspec (1.3.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rake (>= 0.8.7)
+ rspec (~> 1.0)
View
43 Rakefile
@@ -1,6 +1,7 @@
-require File.dirname(__FILE__) + '/lib/gem_template/gems'
+require 'rubygems'
+require 'bundler'
-GemTemplate::Gems.activate %w(rake rspec)
+Bundler.require(:rakefile)
require 'rake'
@@ -29,16 +30,11 @@ end
desc "Build gem(s)"
task :gem do
- old_gemset = ENV['GEMSET']
root = File.expand_path('../', __FILE__)
pkg = "#{root}/pkg"
system "rm -Rf #{pkg}"
- GemTemplate::Gems.gemset_names.each do |gemset|
- ENV['GEMSET'] = gemset.to_s
- system "cd #{root} && gem build gem_template.gemspec"
- system "mkdir -p #{pkg} && mv *.gem pkg"
- end
- ENV['GEMSET'] = old_gemset
+ system "cd #{root} && gem build gem_template.gemspec"
+ system "mkdir -p #{pkg} && mv *.gem pkg"
end
namespace :gem do
@@ -59,35 +55,6 @@ namespace :gem do
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' : ''
-
- GemTemplate::Gems.gemset = gemset if gemset
-
- if dev
- gems = GemTemplate::Gems.gemspec.development_dependencies
- else
- gems = GemTemplate::Gems.gemspec.dependencies
- end
-
- gems.each do |name|
- name = name.to_s
- version = GemTemplate::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
View
2  bin/gem_template
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.expand_path(File.dirname(__FILE__) + "/../lib/gem_template")
+require File.expand_path("../../lib/gem_template", __FILE__)
View
3  config/gemsets.yml
@@ -1,3 +0,0 @@
-gem_template:
- rake: >=0.8.7
- rspec: ~>1.0
View
13 config/gemspec.yml
@@ -1,13 +0,0 @@
-name: gem_template
-version: 0.1.0
-authors:
- -
-email:
-homepage:
-summary:
-description:
-dependencies:
- -
-development_dependencies:
- - rake
- - rspec
View
29 gem_template.gemspec
@@ -1,29 +1,18 @@
# -*- encoding: utf-8 -*-
root = File.expand_path('../', __FILE__)
lib = "#{root}/lib"
+
$:.unshift lib unless $:.include?(lib)
-
-require 'gem_template/gems'
-GemTemplate::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
- 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]
- end
-
- GemTemplate::Gems.development_dependencies.each do |g|
- s.add_development_dependency g.to_s, GemTemplate::Gems.versions[g]
- end
+ s.name = "gem_template"
+ s.version = '0.1.0'
+ s.platform = Gem::Platform::RUBY
+ s.authors = []
+ s.email = []
+ s.homepage = "http://"
+ s.summary = %q{}
+ s.description = %q{}
s.executables = `cd #{root} && git ls-files bin/*`.split("\n").collect { |f| File.basename(f) }
s.files = `cd #{root} && git ls-files`.split("\n")
View
5 lib/gem_template.rb
@@ -1,6 +1,7 @@
-require File.dirname(__FILE__) + '/gem_template/gems'
+require "rubygems"
+require "bundler"
-GemTemplate::Gems.activate %w()
+Bundler.require(:default)
$:.unshift File.dirname(__FILE__)
View
159 lib/gem_template/gems.rb
@@ -1,159 +0,0 @@
-unless defined?(GemTemplate::Gems)
-
- require 'yaml'
-
- module GemTemplate
- 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
View
9 spec/fixtures/gemsets.yml
@@ -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
View
15 spec/fixtures/gemspec.yml
@@ -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
View
249 spec/gem_template/gems_spec.rb
@@ -1,249 +0,0 @@
-require 'spec_helper'
-
-describe GemTemplate::Gems do
-
- before(:each) do
- @old_config = GemTemplate::Gems.config
-
- GemTemplate::Gems.config.gemspec = "#{$root}/spec/fixtures/gemspec.yml"
- GemTemplate::Gems.config.gemsets = [
- "#{$root}/spec/fixtures/gemsets.yml"
- ]
- GemTemplate::Gems.config.warn = true
-
- GemTemplate::Gems.gemspec true
- GemTemplate::Gems.gemset = nil
- end
-
- after(:each) do
- GemTemplate::Gems.config = @old_config
- end
-
- describe :activate do
- it "should activate gems" do
- GemTemplate::Gems.stub!(:gem)
- GemTemplate::Gems.should_receive(:gem).with('rspec', '=1.3.1')
- GemTemplate::Gems.should_receive(:gem).with('rake', '=0.8.7')
- GemTemplate::Gems.activate :rspec, 'rake'
- end
- end
-
- describe :gemset= do
- before(:each) do
- GemTemplate::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
- GemTemplate::Gems.gemset = :default
- end
-
- it "should set @gemset" do
- GemTemplate::Gems.gemset.should == :default
- end
-
- it "should set @gemsets" do
- GemTemplate::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
- GemTemplate::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
- GemTemplate::Gems.dependencies.should == [ :rake, :mysql ]
- GemTemplate::Gems.development_dependencies.should == []
- end
-
- it "should return proper values for Gems.gemset_names" do
- GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
- end
- end
-
- describe :rspec2 do
- before(:each) do
- GemTemplate::Gems.gemset = "rspec2"
- end
-
- it "should set @gemset" do
- GemTemplate::Gems.gemset.should == :rspec2
- end
-
- it "should set @gemsets" do
- GemTemplate::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
- GemTemplate::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
- GemTemplate::Gems.dependencies.should == [ :rake, :mysql2 ]
- GemTemplate::Gems.development_dependencies.should == []
- end
-
- it "should return proper values for Gems.gemset_names" do
- GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
- end
- end
-
- describe :solo do
- before(:each) do
- GemTemplate::Gems.gemset = :solo
- end
-
- it "should set @gemset" do
- GemTemplate::Gems.gemset.should == :solo
- end
-
- it "should set @gemsets" do
- GemTemplate::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
- GemTemplate::Gems.versions.should == {:rake=>">0.8.6"}
- end
-
- it "should return proper values for Gems.dependencies" do
- GemTemplate::Gems.dependencies.should == [:rake]
- GemTemplate::Gems.development_dependencies.should == []
- end
-
- it "should return proper values for Gems.gemset_names" do
- GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
- end
- end
-
- describe :nil do
- before(:each) do
- GemTemplate::Gems.gemset = nil
- end
-
- it "should set everything to nil" do
- GemTemplate::Gems.gemset.should == nil
- GemTemplate::Gems.gemsets.should == nil
- GemTemplate::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 })
- GemTemplate::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 })
- GemTemplate::Gems.send(:gemset_from_loaded_specs).should == :rspec2
- end
- end
-
- describe :reload_gemspec do
- it "should populate @gemspec" do
- GemTemplate::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
- GemTemplate::Gems.gemspec.name.should == "name"
- GemTemplate::Gems.gemspec.version.should == "0.1.0"
- GemTemplate::Gems.gemspec.authors.should == ["Author"]
- GemTemplate::Gems.gemspec.email.should == "email@email.com"
- GemTemplate::Gems.gemspec.homepage.should == "http://github.com/author/name"
- GemTemplate::Gems.gemspec.summary.should == "Summary"
- GemTemplate::Gems.gemspec.description.should == "Description"
- GemTemplate::Gems.gemspec.dependencies.should == [
- "rake",
- { "default" => ["mysql"] },
- { "rspec2" => [ "mysql2" ] }
- ]
- GemTemplate::Gems.gemspec.development_dependencies.should == nil
- end
-
- it "should produce a valid gemspec" do
- GemTemplate::Gems.gemset = :default
- gemspec = File.expand_path("../../../gem_template.gemspec", __FILE__)
- gemspec = eval(File.read(gemspec), binding, gemspec)
- gemspec.validate.should == true
- end
- end
-end
View
13 spec/spec_helper.rb
@@ -1,11 +1,8 @@
-require 'pp'
+require "pp"
+require "bundler"
-$root = File.expand_path('../../', __FILE__)
-require "#{$root}/lib/gem_template/gems"
-
-GemTemplate::Gems.activate :rspec
+Bundler.require(:spec)
-require "#{$root}/lib/gem_template"
+$root = File.expand_path('../../', __FILE__)
-Spec::Runner.configure do |config|
-end
+require "#{$root}/lib/gem_template"
Please sign in to comment.
Something went wrong with that request. Please try again.