Rakefile in rails_errors2html-1.5.0 vs Rakefile in rails_errors2html-1.5.1
- old
+ new
@@ -1,77 +1,70 @@
-This.name =
- "Errors2Html"
+This.author = "Ara T. Howard"
+This.email = "ara.t.howard@gmail.com"
+This.homepage = "https://github.com/ahoward/#{ This.lib }"
-This.synopsis =
- "<%= form_for @post do %> <%= @post.errors.to_html %>"
+task :license do
+ open('LICENSE', 'w'){|fd| fd.puts "Ruby"}
+end
-This.rubyforge_project = 'codeforpeople'
-This.author = "Ara T. Howard"
-This.email = "ara.t.howard@gmail.com"
-This.homepage = "https://github.com/ahoward/#{ This.lib }"
-
-This.setup!
-
-
-
task :default do
puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
end
task :test do
- This.run_tests!
+ run_tests!
end
namespace :test do
- task(:unit){ This.run_tests!(:unit) }
- task(:functional){ This.run_tests!(:functional) }
- task(:integration){ This.run_tests!(:integration) }
+ task(:unit){ run_tests!(:unit) }
+ task(:functional){ run_tests!(:functional) }
+ task(:integration){ run_tests!(:integration) }
end
-def This.run_tests!(which = nil)
+def run_tests!(which = nil)
which ||= '**'
test_dir = File.join(This.dir, "test")
test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
test_rbs = Dir.glob(test_glob).sort
div = ('=' * 119)
line = ('-' * 119)
test_rbs.each_with_index do |test_rb, index|
testno = index + 1
- command = "#{ File.basename(This.ruby) } -I ./lib -I ./test/lib #{ test_rb }"
+ command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
puts
- This.say(div, :color => :cyan, :bold => true)
- This.say("@#{ testno } => ", :bold => true, :method => :print)
- This.say(command, :color => :cyan, :bold => true)
- This.say(line, :color => :cyan, :bold => true)
+ say(div, :color => :cyan, :bold => true)
+ say("@#{ testno } => ", :bold => true, :method => :print)
+ say(command, :color => :cyan, :bold => true)
+ say(line, :color => :cyan, :bold => true)
system(command)
- This.say(line, :color => :cyan, :bold => true)
+ say(line, :color => :cyan, :bold => true)
status = $?.exitstatus
if status.zero?
- This.say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
- This.say("SUCCESS", :color => :green, :bold => true)
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
+ say("SUCCESS", :color => :green, :bold => true)
else
- This.say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
- This.say("FAILURE", :color => :red, :bold => true)
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
+ say("FAILURE", :color => :red, :bold => true)
end
- This.say(line, :color => :cyan, :bold => true)
+ say(line, :color => :cyan, :bold => true)
exit(status) unless status.zero?
end
end
task :gemspec do
ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
- ignore_directories = ['pkg', 'db']
- ignore_files = ['test/log', 'test/db.yml', 'a.rb', 'b.rb'] + Dir['db/*'] + %w'db'
+ ignore_directories = ['pkg']
+ ignore_files = ['test/log']
shiteless =
lambda do |list|
list.delete_if do |entry|
next unless test(?e, entry)
@@ -94,24 +87,24 @@
object = This.object
version = This.version
files = shiteless[Dir::glob("**/**")]
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
#has_rdoc = true #File.exist?('doc')
- test_files = test(?e, "test/#{ lib }.rb") ? "test/#{ lib }.rb" : nil
- summary = This.summary || This.synopsis || "#{ lib } kicks the ass"
- description = This.description || summary
+ test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
+ summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
+ description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
+ license = object.respond_to?(:license) ? object.license : "Ruby"
if This.extensions.nil?
This.extensions = []
extensions = This.extensions
%w( Makefile configure extconf.rb ).each do |ext|
extensions << ext if File.exists?(ext)
end
end
extensions = [extensions].flatten.compact
-# TODO
if This.dependencies.nil?
dependencies = []
else
case This.dependencies
when Hash
@@ -121,23 +114,24 @@
end
end
template =
if test(?e, 'gemspec.erb')
- This.template_for{ IO.read('gemspec.erb') }
+ Template{ IO.read('gemspec.erb') }
else
- This.template_for {
+ Template {
<<-__
## <%= lib %>.gemspec
#
Gem::Specification::new do |spec|
spec.name = <%= lib.inspect %>
spec.version = <%= version.inspect %>
spec.platform = Gem::Platform::RUBY
spec.summary = <%= lib.inspect %>
spec.description = <%= description.inspect %>
+ spec.license = <%= license.inspect %>
spec.files =\n<%= files.sort.pretty_inspect %>
spec.executables = <%= executables.inspect %>
spec.require_path = "lib"
@@ -148,33 +142,32 @@
spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>)
<% end %>
spec.extensions.push(*<%= extensions.inspect %>)
- spec.rubyforge_project = <%= This.rubyforge_project.inspect %>
spec.author = <%= This.author.inspect %>
spec.email = <%= This.email.inspect %>
spec.homepage = <%= This.homepage.inspect %>
end
__
}
end
- FileUtils.mkdir_p(This.pkgdir)
+ Fu.mkdir_p(This.pkgdir)
gemspec = "#{ lib }.gemspec"
open(gemspec, "w"){|fd| fd.puts(template)}
This.gemspec = gemspec
end
task :gem => [:clean, :gemspec] do
- FileUtils.mkdir_p(This.pkgdir)
+ Fu.mkdir_p(This.pkgdir)
before = Dir['*.gem']
cmd = "gem build #{ This.gemspec }"
`#{ cmd }`
after = Dir['*.gem']
gem = ((after - before).first || after.first) or abort('no gem!')
- FileUtils.mv(gem, This.pkgdir)
+ Fu.mv(gem, This.pkgdir)
This.gem = File.join(This.pkgdir, File.basename(gem))
end
task :readme do
samples = ''
@@ -184,25 +177,25 @@
Dir['sample*/*'].sort.each do |sample|
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
cmd = "cat #{ sample }"
- samples << This.util.indent(prompt + cmd, 2) << "\n\n"
- samples << This.util.indent(`#{ cmd }`, 4) << "\n"
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
+ samples << Util.indent(`#{ cmd }`, 4) << "\n"
cmd = "ruby #{ sample }"
- samples << This.util.indent(prompt + cmd, 2) << "\n\n"
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
- samples << This.util.indent(`#{ cmd } 2>&1`, 4) << "\n"
+ samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
end
template =
- if test(?e, 'readme.erb')
- This.template_for{ IO.read('readme.erb') }
+ if test(?e, 'README.erb')
+ Template{ IO.read('README.erb') }
else
- This.template_for {
+ Template {
<<-__
NAME
#{ lib }
DESCRIPTION
@@ -217,32 +210,24 @@
end
open("README", "w"){|fd| fd.puts template}
end
-
task :clean do
- Dir[File.join(This.pkgdir, '**/**')].each{|entry| FileUtils.rm_rf(entry)}
+ Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
end
-
task :release => [:clean, :gemspec, :gem] do
gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
raise "which one? : #{ gems.inspect }" if gems.size > 1
raise "no gems?" if gems.size < 1
cmd = "gem push #{ This.gem }"
puts cmd
puts
system(cmd)
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
-
- #cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
- #puts cmd
- #puts
- #system(cmd)
- #abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
end
@@ -250,147 +235,105 @@
BEGIN {
# support for this rakefile
#
$VERBOSE = nil
+ require 'ostruct'
require 'erb'
require 'fileutils'
require 'rbconfig'
require 'pp'
+# fu shortcut
+#
+ Fu = FileUtils
+
# cache a bunch of stuff about this rakefile/environment
#
+ This = OpenStruct.new
- This =
- Class.new(Hash) do
-
- def method_missing(method, *args, &block)
- if method.to_s =~ /=/
- key = method.to_s.chomp('=')
- value = block ? block : args.shift
- self[key] = value
- else
- key = method.to_s
- if block
- value = block
- self[key] = value
- else
- value = self[key]
-
- if value.respond_to?(:call)
- self[key] = value.call()
- else
- value
- end
- end
- end
- end
-
- def inspect
- expand!
- PP.pp(self, '')
- end
-
- def expand!
- keys.each do |key|
- value = self[key]
- if value.respond_to?(:call)
- self[key] = value.call()
- end
- end
- end
-
- end.new()
-
This.file = File.expand_path(__FILE__)
This.dir = File.dirname(This.file)
This.pkgdir = File.join(This.dir, 'pkg')
+ This.lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
-# defaults
+# load _lib
#
- This.lib do
- File.basename(Dir.pwd)
- end
+ This._lib = "./lib/#{ This.lib }/_lib.rb"
+ require This._lib
- def This.setup!
- begin
- require "./lib/#{ This.lib }"
- rescue LoadError
- abort("could not load #{ This.lib }")
+# extract name from _lib
+#
+ lines = IO.binread(This._lib).split("\n")
+ re = %r`\A \s* (module|class) \s+ ([^\s]+) \s* \z`iomx
+ name = nil
+ lines.each do |line|
+ match = line.match(re)
+ if match
+ name = match.to_a.last
+ break
end
end
-
- This.name do
- This.name = This.lib.capitalize
+ unless name
+ abort "could not extract `name` from #{ This._lib }"
end
+ This.name = name
- This.object do
- begin
- This.object = eval(This.name)
- rescue Object
- abort("could not determine object from #{ This.name }")
- end
- end
+# now, fully grok This
+#
+ This.object = eval(This.name)
- This.version do
- This.object.send(:version)
- end
+ version = This.object.send(:version)
+ This.version = version
- This.dependencies do
- if This.object.respond_to?(:dependencies)
- This.object.dependencies
- end
+ if This.object.respond_to?(:dependencies)
+ This.dependencies = This.object.dependencies
end
- This.ruby do
- c = Config::CONFIG
- bindir = c["bindir"] || c['BINDIR']
- ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
- ruby_ext = c['EXEEXT'] || ''
- File.join(bindir, (ruby_install_name + ruby_ext))
- end
+# discover full path to this ruby executable
+#
+ c = RbConfig::CONFIG
+ bindir = c["bindir"] || c['BINDIR']
+ ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
+ ruby_ext = c['EXEEXT'] || ''
+ ruby = File.join(bindir, (ruby_install_name + ruby_ext))
+ This.ruby = ruby
# some utils
#
- This.util = Module.new do
+ module Util
def indent(s, n = 2)
s = unindent(s)
ws = ' ' * n
s.gsub(%r/^/, ws)
end
def unindent(s)
indent = nil
s.each_line do |line|
- next if line =~ %r/^\s*$/
- indent = line[%r/^\s*/] and break
- end
- indent ? s.gsub(%r/^#{ indent }/, "") : s
+ next if line =~ %r/^\s*$/
+ indent = line[%r/^\s*/] and break
end
-
+ indent ? s.gsub(%r/^#{ indent }/, "") : s
+ end
extend self
end
# template support
#
- This.template = Class.new do
+ class Template
def initialize(&block)
@block = block
@template = block.call.to_s
end
-
def expand(b=nil)
- ERB.new(This.util.unindent(@template)).result((b||@block).binding)
+ ERB.new(Util.unindent(@template)).result((b||@block).binding)
end
-
alias_method 'to_s', 'expand'
end
+ def Template(*args, &block) Template.new(*args, &block) end
- def This.template_for(*args, &block)
- This.template.new(*args, &block)
- end
-
# colored console output support
#
This.ansi = {
:clear => "\e[0m",
:reset => "\e[0m",
@@ -418,20 +361,19 @@
:on_blue => "\e[44m",
:on_magenta => "\e[45m",
:on_cyan => "\e[46m",
:on_white => "\e[47m"
}
-
- def This.say(something, *args)
+ def say(phrase, *args)
options = args.last.is_a?(Hash) ? args.pop : {}
options[:color] = args.shift.to_s.to_sym unless args.empty?
keys = options.keys
keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
color = options[:color]
bold = options.has_key?(:bold)
- parts = [something]
+ parts = [phrase]
parts.unshift(This.ansi[color]) if color
parts.unshift(This.ansi[:bold]) if bold
parts.push(This.ansi[:clear]) if parts.size > 1
method = options[:method] || :puts