diff --git a/lib/gorp/config.rb b/lib/gorp/config.rb index de7e845..7daf1b0 100644 --- a/lib/gorp/config.rb +++ b/lib/gorp/config.rb @@ -17,14 +17,14 @@ def self.load(config) @@hash end - def self.[](name, default=nil) + def self.get hash = @@hash.dup rails = hash.delete('rails') if rails - version = File.read("#$rails/RAILS_VERSION").chomp + hash['rails'] = version = File.read("#$rails/RAILS_VERSION").chomp rails.each do |pattern, config| - if version =~ Regexp.new(Regexp.escape(pattern).gsub('\*','.*?')) + if version =~ Regexp.new('^'+Regexp.escape(pattern).gsub('\*','.*?')) hash.merge! config end end @@ -32,14 +32,19 @@ def self.[](name, default=nil) ruby = hash.delete('ruby') if ruby - version = RUBY_VERSION + hash['ruby'] = version = RUBY_VERSION ruby.each do |pattern, config| - if version =~ Regexp.new(Regexp.escape(pattern).gsub('\*','.*?')) + if version =~ Regexp.new('^'+Regexp.escape(pattern).gsub('\*','.*?')) hash.merge! config end end end + hash + end + + def self.[](name, default=nil) + hash = self.get if hash.has_key? name.to_s hash[name.to_s] else diff --git a/lib/gorp/env.rb b/lib/gorp/env.rb index 89bcd1f..bbe9ff4 100644 --- a/lib/gorp/env.rb +++ b/lib/gorp/env.rb @@ -90,9 +90,15 @@ def self.dump_env end if File.exist? 'Gemfile' - log :cmd, 'rake about' - $x.pre 'rake about', :class=>'stdin' - about = `rake about`.sub(/^(Middleware\s+)(.*)/) { + if File.read("#$rails/RAILS_VERSION") =~ /^[34]/ + cmd = 'rake about' + else + cmd = 'rails about' + end + + log :cmd, cmd + $x.pre cmd, :class=>'stdin' + about = `#{cmd}`.sub(/^(Middleware\s+)(.*)/) { term,dfn=$1,$2 term+dfn.gsub(', ', ",\n" + ' ' * term.length) } @@ -149,7 +155,24 @@ def self.dump_env cmd "uname -srm" end - rescue + config = Gorp::Config.get + if config and not config.empty? + $x.pre 'Gorp.config.get', :class=>'stdin' + $x.table do + config.sort.each do |name, value| + $x.tr do + $x.td name + $x.td value.inspect + end + end + end + end + rescue Exception => e + $x.pre :class => 'traceback' do + STDERR.puts e.inspect + $x.text! "#{e.inspect}\n" + e.backtrace.each {|line| $x.text! " #{line}\n"} + end end def self.log type, message