diff options
| author | Jack Nagel | 2014-09-18 14:16:07 -0500 |
|---|---|---|
| committer | Jack Nagel | 2014-09-18 14:16:07 -0500 |
| commit | 3bbc9998a52b86b206465c887e75ee419418c26d (patch) | |
| tree | 622674f6d85c874793483740c52397b1de30a6f7 /Library/Homebrew/debrew | |
| parent | 67a916427880df69ae34215c9d03cda4849f1ae6 (diff) | |
| download | brew-3bbc9998a52b86b206465c887e75ee419418c26d.tar.bz2 | |
Rewrite debugger to remove monkeypatches and use of call/cc
Diffstat (limited to 'Library/Homebrew/debrew')
| -rw-r--r-- | Library/Homebrew/debrew/exception.rb | 7 | ||||
| -rw-r--r-- | Library/Homebrew/debrew/menu.rb | 39 | ||||
| -rw-r--r-- | Library/Homebrew/debrew/raise_plus.rb | 46 |
3 files changed, 0 insertions, 92 deletions
diff --git a/Library/Homebrew/debrew/exception.rb b/Library/Homebrew/debrew/exception.rb deleted file mode 100644 index da8e56dae..000000000 --- a/Library/Homebrew/debrew/exception.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Exception - attr_accessor :continuation - - def restart(&block) - continuation.call block - end -end diff --git a/Library/Homebrew/debrew/menu.rb b/Library/Homebrew/debrew/menu.rb deleted file mode 100644 index c59c500b8..000000000 --- a/Library/Homebrew/debrew/menu.rb +++ /dev/null @@ -1,39 +0,0 @@ -class Menu - attr_accessor :prompt - attr_accessor :entries - - def initialize - @entries = [] - end - - def choice(name, &action) - entries << { :name => name, :action => action } - end -end - -def choose - menu = Menu.new - yield menu - - choice = nil - while choice.nil? - menu.entries.each_with_index do |entry, i| - puts "#{i+1}. #{entry[:name]}" - end - print menu.prompt unless menu.prompt.nil? - reply = $stdin.gets.chomp - - i = reply.to_i - if i > 0 - choice = menu.entries[i-1] - else - possible = menu.entries.find_all {|e| e[:name].to_s.start_with? reply } - case possible.size - when 0 then puts "No such option" - when 1 then choice = possible.first - else puts "Multiple options match: #{possible.map{|e| e[:name]}.join(' ')}" - end - end - end - choice[:action].call -end diff --git a/Library/Homebrew/debrew/raise_plus.rb b/Library/Homebrew/debrew/raise_plus.rb deleted file mode 100644 index 29bf4106a..000000000 --- a/Library/Homebrew/debrew/raise_plus.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'continuation' if RUBY_VERSION.to_f >= 1.9 - -class Exception - attr_accessor :continuation - - def restart(&block) - continuation.call block - end -end - -module RaisePlus - alias :original_raise :raise - - private - - def raise(*args) - exception = case - when args.size == 0 - $!.nil? ? RuntimeError.exception : $! - when args.size == 1 && args[0].is_a?(String) - RuntimeError.exception(args[0]) - when args.size == 2 && args[0].is_a?(Exception) - args[0].exception(args[1]) - when args[0].is_a?(Class) && args[0].ancestors.include?(Exception) - args[0].exception(args[1]) - else - args[0] - end - - # passing something other than a String or Exception is illegal, but if someone does it anyway, - # that object won't have backtrace or continuation methods. in that case, let's pass it on to - # the original raise, which will reject it - return super exception unless exception.is_a?(Exception) - - # keep original backtrace if reraising - exception.set_backtrace(args.size >= 3 ? args[2] : caller) if exception.backtrace.nil? - - blk = callcc do |cc| - exception.continuation = cc - super exception - end - blk.call unless blk.nil? - end - - alias :fail :raise -end |
