Permalink
Browse files

Merge branch 'master' into rails

  • Loading branch information...
2 parents f12165c + 7e8a9b6 commit e908b55002a3ccc8a346b72b09ab26e6460f6d64 @winton committed Sep 19, 2011
View
@@ -1,5 +1,4 @@
.DS_Store
*.gem
-coverage
pkg
tmp
View
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+gem 'rake', '>=0.8.7', :group => :rakefile
+gem 'rspec', '~>1.0', :group => [ :rakefile, :spec ]
View
@@ -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
@@ -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
@@ -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
@@ -1,3 +0,0 @@
-gem_template:
- rake: >=0.8.7
- rspec: ~>1.0
View
@@ -1,13 +0,0 @@
-name: gem_template
-version: 0.1.0
-authors:
- -
-email:
-homepage:
-summary:
-description:
-dependencies:
- -
-development_dependencies:
- - rake
- - rspec
View
@@ -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
@@ -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__)
@@ -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
@@ -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
@@ -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
Oops, something went wrong. Retry.

0 comments on commit e908b55

Please sign in to comment.