Permalink
Browse files

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

Conflicts:
	Rakefile
	gem_template.gemspec
	lib/gem_template.rb
	lib/gem_template/gems.rb
	spec/spec_helper.rb
  • Loading branch information...
2 parents 3bb4a93 + 7bbe1a5 commit 2f25892456733aed312d5593b8737c3ef180df00 @winton committed Dec 29, 2010
View
@@ -1,4 +1,4 @@
-Copyright (c) 2010 Winton Welsh
+Copyright (c) 2010
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
View
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/lib/acts_as_archive/gems'
-ActsAsArchive::Gems.require(:rake)
+ActsAsArchive::Gems.activate %w(rake rspec)
require 'rake'
require 'rake/gempackagetask'
@@ -76,30 +76,4 @@ task :gemspec do
end
task :package => :gemspec
-task :default => :spec
-
-# 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['**/acts_as_archive*']
- begin
- from = dir.pop
- if from
- to = from.split('/')
- to[-1].gsub!('acts_as_archive', name)
- FileUtils.mv(from, to.join('/'))
- end
- end while dir.length > 0
- Dir["**/*"].each do |path|
- if File.file?(path)
- `sed -i '' 's/acts_as_archive/#{name}/g' #{path}`
- `sed -i '' 's/ActsAsArchive/#{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
+task :default => :spec
@@ -1,29 +1,21 @@
# -*- encoding: utf-8 -*-
-lib = File.expand_path('../lib/', __FILE__)
-$:.unshift lib unless $:.include?(lib)
-
-require 'acts_as_archive/gems'
-require 'acts_as_archive/version'
-
Gem::Specification.new do |s|
- s.name = "acts_as_archive"
- s.version = ActsAsArchive::VERSION
- s.platform = Gem::Platform::RUBY
- s.authors = ["Winton Welsh"]
- s.email = ["mail@wintoni.us"]
- s.homepage = "http://github.com/winton/acts_as_archive"
- s.summary = "Don't delete your records, move them to a different table"
- s.description = "Don't delete your records, move them to a different table"
+ ActsAsArchive::Gems.gemspec.hash.each do |key, value|
+ unless %w(dependencies development_dependencies).include?(key)
+ s.send "#{key}=", value
+ end
+ end
- ActsAsArchive::Gems::TYPES[:gemspec].each do |g|
- s.add_dependency g.to_s, ActsAsArchive::Gems::VERSIONS[g]
+ ActsAsArchive::Gems.gemspec.dependencies.each do |g|
+ s.add_dependency g.to_s, ActsAsArchive::Gems.versions[g]
end
- ActsAsArchive::Gems::TYPES[:gemspec_dev].each do |g|
- s.add_development_dependency g.to_s, ActsAsArchive::Gems::VERSIONS[g]
+ ActsAsArchive::Gems.gemspec.development_dependencies.each do |g|
+ s.add_development_dependency g.to_s, ActsAsArchive::Gems.versions[g]
end
- s.files = Dir.glob("{bin,lib}/**/*") + %w(LICENSE README.md)
- s.executables = Dir.glob("{bin}/*").collect { |f| File.basename(f) }
- s.require_path = 'lib'
+ s.executables = `git ls-files -- {bin}/*`.split("\n").collect { |f| File.basename(f) }
+ s.files = `git ls-files`.split("\n")
+ s.require_paths = %w(lib)
+ s.test_files = `git ls-files -- {features,test,spec}/*`.split("\n")
end
View
@@ -0,0 +1,11 @@
+acts_as_archive:
+ rake: =0.8.7
+ rspec: =1.3.1
+ default:
+ activesupport: =3.0.3
+ active_wrapper: =0.3.4
+ also_migrate: =0.2.1
+ externals: =1.0.2
+ framework_fixture: =0.1.2
+ mover: =0.3.3
+ rack-test: =0.5.6
View
@@ -0,0 +1,15 @@
+name: acts_as_archive
+version: 0.2.5
+authors:
+ - Winton Welsh
+email: mail@wintoni.us
+homepage: http://github.com/winton/acts_as_archive
+summary: Don't delete your records, move them to a different table
+description: Don't delete your records, move them to a different table. Like acts_as_paranoid, but doesn't mess with your SQL queries.
+dependencies:
+ - also_migrate
+ - mover
+development_dependencies:
+ - active_wrapper
+ - externals
+ - rspec
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/acts_as_archive/gems'
-ActsAsArchive::Gems.require(:lib)
+ActsAsArchive::Gems.activate %w(also_migrate mover)
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../vendor/also_migrate/lib')
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../vendor/mover/lib')
@@ -10,8 +10,6 @@
$:.unshift File.dirname(__FILE__)
-require 'acts_as_archive/version'
-
class ActsAsArchive
class <<self
@@ -1,49 +1,105 @@
unless defined?(ActsAsArchive::Gems)
- require 'rubygems'
+ require 'ostruct'
+ require 'yaml'
class ActsAsArchive
- class Gems
-
- VERSIONS = {
- :activesupport => '=3.0.3',
- :active_wrapper => '=0.3.4',
- :also_migrate => '0.2.1',
- :externals => '1.0.2',
- :framework_fixture => '0.1.2',
- :mover => '0.3.3',
- :'rack-test' => '0.5.6',
- :rake => '=0.8.7',
- :rspec => '=1.3.1'
- }
-
- TYPES = {
- :gemspec => [ :also_migrate, :mover ],
- :gemspec_dev => [ :active_wrapper, :externals, :rspec ],
- :lib => [ :also_migrate, :mover ],
- :rake => [ :rake, :rspec ],
- :spec => [ :'rack-test', :rspec ],
- :spec_first => [ :framework_fixture ],
- :spec_non_framework => [ :activesupport, :active_wrapper ],
- :spec_rake => [ :active_wrapper ]
- }
-
+ module Gems
class <<self
- def lockfile
- file = File.expand_path('../../../gems', __FILE__)
- unless File.exists?(file)
- File.open(file, 'w') do |f|
- Gem.loaded_specs.each do |key, value|
- f.puts "#{key} #{value.version.version}"
+ attr_accessor :configs, :gemset, :gemsets, :gemspec, :testing, :versions, :warn
+
+ Gems.configs = [ "#{File.expand_path('../../../', __FILE__)}/config/gemsets.yml" ]
+ Gems.testing = false
+ Gems.warn = true
+
+ class Gemspec
+ attr_accessor :hash
+
+ def initialize(hash)
+ @hash = hash
+ @hash.each do |key, value|
+ self.class.send(:define_method, key) { value }
+ end
+ end
+ end
+
+ def activate(*gems)
+ begin
+ require 'rubygems' if !defined?(::Gem) || @testing
+ rescue LoadError
+ puts "rubygems library could not be required" if @warn
+ end
+
+ self.gemset = :default unless defined?(@gemset) && @gemset
+
+ gems.flatten.collect(&:to_sym).each do |name|
+ version = @versions[name]
+ if defined?(gem)
+ gem name.to_s, version
+ else
+ puts "#{name} #{"(#{version})" if version} failed to activate" if @warn
+ end
+ end
+ end
+
+ def gemset=(gemset)
+ if gemset
+ @gemset = gemset.to_sym
+
+ @gemsets = @configs.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?(::String)
+ hash[key] = value
+ elsif value.is_a?(::Hash) && key == @gemset
+ value.each { |k, v| hash[k] = v }
end
+ hash
end
+ else
+ @gemset = nil
+ @gemsets = nil
+ @versions = nil
end
end
- def require(type=nil)
- (TYPES[type] || TYPES.values.flatten.compact).each do |name|
- gem name.to_s, VERSIONS[name]
+ def reload_gemspec
+ data =
+ YAML::load(
+ File.read(
+ "#{File.expand_path('../../../', __FILE__)}/config/gemspec.yml"
+ )
+ ) rescue {}
+
+ @gemspec = Gemspec.new(data)
+ end
+
+ Gems.reload_gemspec
+
+ 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 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
@@ -1,3 +0,0 @@
-class ActsAsArchive
- VERSION = "0.2.5" unless defined?(::ActsAsArchive::VERSION)
-end
View
@@ -1,5 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + '/../lib/acts_as_archive/gems')
-ActsAsArchive::Gems.require(:spec_rake)
+ActsAsArchive::Gems.activate :active_wrapper
require 'active_wrapper/tasks'
Oops, something went wrong.

0 comments on commit 2f25892

Please sign in to comment.