Permalink
Browse files

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

Conflicts:
	README.md
	Rakefile
	bin/gem_template
	lib/gem_template.rb
	rails/init.rb
	require.rb
	spec/db/log/.gitignore
	spec/spec_helper.rb
  • Loading branch information...
winton committed Dec 6, 2010
2 parents 3cf85ae + ceab4b3 commit e9cd7b6b8d0cd39d570159b83904318817c15782
View
@@ -1,6 +1,5 @@
.DS_Store
*.gem
-*.gemspec
coverage
pkg
spec/db/log/*.log
View
@@ -1,4 +1,4 @@
-Copyright (c) 2009 Winton Welsh
+Copyright (c) 2010 Winton Welsh
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
@@ -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.
File renamed without changes.
View
106 Rakefile
@@ -1,9 +1,105 @@
-require "#{File.dirname(__FILE__)}/require"
-Require.rakefile!
+require File.dirname(__FILE__) + '/lib/acts_as_archive/gems'
-desc "Generate gemspec"
+ActsAsArchive::Gems.require(:rake)
+
+require 'rake'
+require 'rake/gempackagetask'
+require 'spec/rake/spectask'
+
+def gemspec
+ @gemspec ||= begin
+ file = File.expand_path('../acts_as_archive.gemspec', __FILE__)
+ eval(File.read(file), binding, file)
+ end
+end
+
+if defined?(Rake::GemPackageTask)
+ Rake::GemPackageTask.new(gemspec) do |pkg|
+ pkg.gem_spec = gemspec
+ end
+ task :gem => :gemspec
+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
+end
+
+namespace :gems do
+ desc "Install gems (DEV=1|0 DOCS=1|0 SUDO=1|0)"
+ task :install do
+ file = File.dirname(__FILE__) + '/gems'
+ sudo = (ENV['SUDO'] ||= '0').to_i
+ docs = (ENV['DOCS'] ||= '0').to_i
+ sudo = sudo == 1 ? 'sudo' : ''
+ docs = docs == 1 ? '' : '--no-ri --no-rdoc'
+ gems = []
+
+ if File.exists?(file)
+ File.open(file, 'r') do |f|
+ gems = f.readlines.collect do |line|
+ line.split(' ')
+ end
+ end
+ else
+ gems = ActsAsArchive::Gems::TYPES[:gemspec]
+ gems = ActsAsArchive::Gems::TYPES[:gemspec_dev] if ENV['DEV'] == '1'
+ gems.collect! do |g|
+ [ g.to_s, ActsAsArchive::Gems::VERSIONS[g] ]
+ end
+ end
+
+ gems.each do |(name, version)|
+ 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 "Install gem locally"
+task :install => :package do
+ sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
+end
+
+desc "Validate the gemspec"
task :gemspec do
- File.open("#{Rake.original_dir}/acts_as_archive.gemspec", 'w') do |f|
- f.write(Require.gemspec.to_ruby)
+ gemspec.validate
+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
View
@@ -1,32 +1,29 @@
# -*- encoding: utf-8 -*-
+lib = File.expand_path('../lib/', __FILE__)
+$:.unshift lib unless $:.include?(lib)
-Gem::Specification.new do |s|
- s.name = %q{acts_as_archive}
- s.version = "0.2.5"
+require 'acts_as_archive/gems'
+require 'acts_as_archive/version'
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_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.date = %q{2010-05-07}
- s.default_executable = %q{acts_as_archive}
- s.email = %q{mail@wintoni.us}
- s.executables = ["acts_as_archive"]
- s.extra_rdoc_files = ["README.markdown"]
- s.files = ["bin", "bin/acts_as_archive", "init.rb", "lib", "lib/acts_as_archive", "lib/acts_as_archive/base", "lib/acts_as_archive/base/adapters", "lib/acts_as_archive/base/adapters/mysql.rb", "lib/acts_as_archive/base/adapters/postgresql.rb", "lib/acts_as_archive/base/destroy.rb", "lib/acts_as_archive/base/restore.rb", "lib/acts_as_archive/base/table.rb", "lib/acts_as_archive/base.rb", "lib/acts_as_archive/migration.rb", "lib/acts_as_archive.rb", "MIT-LICENSE", "rails", "rails/init.rb", "Rakefile", "README.markdown", "require.rb", "spec", "spec/acts_as_archive", "spec/acts_as_archive/base", "spec/acts_as_archive/base/destroy_spec.rb", "spec/acts_as_archive/base/restore_spec.rb", "spec/acts_as_archive/base/table_spec.rb", "spec/acts_as_archive/base_spec.rb", "spec/acts_as_archive/migration_spec.rb", "spec/db", "spec/db/config", "spec/db/config/database.mysql.yml", "spec/db/config/database.postgresql.yml", "spec/db/log", "spec/db/migrate", "spec/db/migrate/001_add_to_articles.rb", "spec/db/migrate_2", "spec/db/migrate_2/001_add_to_articles.rb", "spec/db/models", "spec/db/models/article.rb", "spec/spec.opts", "spec/spec_helper.rb"]
- s.homepage = %q{http://github.com/winton/acts_as_archive}
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.5}
- s.summary = %q{Don't delete your records, move them to a different table}
-
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
+ 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"
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<require>, ["= 0.2.1"])
- else
- s.add_dependency(%q<require>, ["= 0.2.1"])
- end
- else
- s.add_dependency(%q<require>, ["= 0.2.1"])
+ ActsAsArchive::Gems::TYPES[:gemspec].each do |g|
+ s.add_dependency g.to_s, ActsAsArchive::Gems::VERSIONS[g]
end
-end
+
+ ActsAsArchive::Gems::TYPES[:gemspec_dev].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'
+end
View
@@ -1,5 +1,17 @@
-require File.expand_path("#{File.dirname(__FILE__)}/../require")
-Require.lib!
+require File.dirname(__FILE__) + '/acts_as_archive/gems'
+
+ActsAsArchive::Gems.require(:lib)
+
+$:.unshift File.dirname(__FILE__) + '/acts_as_archive'
+
+require 'base'
+require 'base/adapters/mysql'
+require 'base/adapters/postgresql'
+require 'base/destroy'
+require 'base/restore'
+require 'base/table'
+require 'migration'
+require 'version'
module ActsAsArchive
@@ -16,4 +28,7 @@ def self.update(*models)
end
end
end
-end
+end
+
+ActiveRecord::Base.send(:include, ActsAsArchive::Base)
+ActiveRecord::Migration.send(:include, ActsAsArchive::Migration)
@@ -28,4 +28,4 @@ class Archive < ActiveRecord::Base
end
end
end
-end
+end
@@ -37,4 +37,4 @@ def archive_table_indexed_columns
end
end
end
-end
+end
@@ -68,4 +68,4 @@ def destroy_with_callbacks!
end
end
end
-end
+end
@@ -33,4 +33,4 @@ module InstanceMethods
end
end
end
-end
+end
@@ -106,4 +106,4 @@ module InstanceMethods
end
end
end
-end
+end
@@ -0,0 +1,43 @@
+unless defined?(ActsAsArchive::Gems)
+
+ require 'rubygems'
+
+ module ActsAsArchive
+ class Gems
+
+ VERSIONS = {
+ :activerecord => '=3.0.3',
+ :rake => '=0.8.7',
+ :rspec => '=1.3.1'
+ }
+
+ TYPES = {
+ :gemspec => [],
+ :gemspec_dev => [ :rspec ],
+ :lib => [],
+ :rake => [ :rake, :rspec ],
+ :spec => [ :activerecord, :rspec ]
+ }
+
+ 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}"
+ end
+ end
+ end
+ end
+
+ def require(type=nil)
+ (TYPES[type] || TYPES.values.flatten.compact).each do |name|
+ gem name.to_s, VERSIONS[name]
+ end
+ end
+ end
+ end
+ end
+end
@@ -46,4 +46,4 @@ def method_missing_with_archive(method, *arguments, &block)
module InstanceMethods
end
end
-end
+end
@@ -0,0 +1,3 @@
+module ActsAsArchive
+ VERSION = "0.2.5" unless defined?(::ActsAsArchive::VERSION)
+end
View
@@ -1,5 +1 @@
-require File.expand_path("#{File.dirname(__FILE__)}/../require")
-Require.rails_init!
-
-ActiveRecord::Base.send(:include, ActsAsArchive::Base)
-ActiveRecord::Migration.send(:include, ActsAsArchive::Migration)
+require File.expand_path(File.dirname(__FILE__) + '/../lib/acts_as_archive')
View
@@ -1,49 +0,0 @@
-require 'rubygems'
-gem 'require'
-require 'require'
-
-Require do
- gem(:activerecord) { require 'active_record' }
- gem :require, '=0.2.1'
- gem(:rake, '=0.8.7') { require 'rake' }
- gem :rspec, '=1.3.0'
-
- gemspec do
- author 'Winton Welsh'
- dependencies do
- gem :require
- end
- email 'mail@wintoni.us'
- name 'acts_as_archive'
- homepage "http://github.com/winton/#{name}"
- summary "Don't delete your records, move them to a different table"
- version '0.2.5'
- end
-
- lib do
- require "lib/acts_as_archive/base"
- require "lib/acts_as_archive/base/adapters/mysql"
- require "lib/acts_as_archive/base/adapters/postgresql"
- require "lib/acts_as_archive/base/destroy"
- require "lib/acts_as_archive/base/restore"
- require "lib/acts_as_archive/base/table"
- require "lib/acts_as_archive/migration"
- end
-
- rails_init { require 'lib/acts_as_archive' }
-
- rakefile do
- gem(:rake) { require 'rake/gempackagetask' }
- gem(:rspec) { require 'spec/rake/spectask' }
- require 'require/tasks'
- end
-
- spec_helper do
- require 'require/spec_helper'
- gem :activerecord
- require 'logger'
- require 'yaml'
- require 'pp'
- require 'rails/init'
- end
-end
@@ -114,4 +114,4 @@
end
end
end
-end
+end
@@ -71,4 +71,4 @@
Article::Archive.count.should == 0
end
end
-end
+end
@@ -34,4 +34,4 @@
(@old_archive_columns - @new_archive_columns).should == []
end
end
-end
+end
@@ -3,4 +3,4 @@ test:
database: acts_as_archive
username: root
password:
- host: localhost
+ host: localhost
Oops, something went wrong.

0 comments on commit e9cd7b6

Please sign in to comment.