Skip to content

Commit

Permalink
fix version check; dump test config
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Jan 31, 2016
1 parent dc024ee commit c6728b0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
15 changes: 10 additions & 5 deletions lib/gorp/config.rb
Expand Up @@ -17,29 +17,34 @@ 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
end

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
Expand Down
31 changes: 27 additions & 4 deletions lib/gorp/env.rb
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c6728b0

Please sign in to comment.