Module: Kernel
- Defined in:
- lib/amp/dependencies/zip/ziprequire.rb,
lib/amp/commands/hooks.rb,
lib/amp/support/support.rb,
lib/amp/support/ruby_19_compatibility.rb,
lib/amp/support/support.rb
Overview
:nodoc:all
Instance Method Summary collapse
- #abort(str) ⇒ Object
- #already_loaded?(moduleName) ⇒ Boolean
- #ensure_rb_extension(aString) ⇒ Object
-
#full_backtrace_please { ... } ⇒ Object
The built-in Ruby 1.8.x implementation will only show a certain number of context lines at the start and end of its backtrace when an exception is raised.
- #get_resource(resourceName, &aProc) ⇒ Object
-
#hook(names) { ... } ⇒ Object
Adds a hook to each of the provided hook entry points.
-
#ignore_missing_files { ... } ⇒ Object
Allows any code called within the block to access non-existent files without raising an exception.
- #oldRequire ⇒ Object
- #require(moduleName) ⇒ Object
- #ruby_19? ⇒ Boolean
- #zip_require(moduleName) ⇒ Object
Instance Method Details
#abort(str) ⇒ Object
45 46 47 |
# File 'lib/amp/support/support.rb', line 45 def abort(str) AbortError.new str end |
#already_loaded?(moduleName) ⇒ Boolean
78 79 80 81 |
# File 'lib/amp/dependencies/zip/ziprequire.rb', line 78 def already_loaded?(moduleName) moduleRE = Regexp.new("^"+moduleName+"(\.rb|\.so|\.dll|\.o)?$") $".detect { |e| e =~ moduleRE } != nil end |
#ensure_rb_extension(aString) ⇒ Object
83 84 85 |
# File 'lib/amp/dependencies/zip/ziprequire.rb', line 83 def ensure_rb_extension(aString) aString.sub(/(\.rb)?$/i, ".rb") end |
#full_backtrace_please { ... } ⇒ Object
The built-in Ruby 1.8.x implementation will only show a certain number of context lines at the start and end of its backtrace when an exception is raised. All other levels of the stack will be labeled “… 15 levels …” Sadly, sometimes some important information is in those 15 levels, and without patching the interpreter, there’s no way to just disable that abbreviation.
So, we simply catch all exceptions, print their full backtrace, and then exit!
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/amp/support/support.rb', line 216 def full_backtrace_please = ["***** Left engine failure *****", "***** Ejection system error *****", "***** Vaccuum in booster engine *****" ][rand(3)] begin yield rescue AbortError => e Amp::UI.say "Operation aborted." raise rescue StandardError => e Amp::UI.say Amp::UI.say e.to_s e.backtrace.each {|err| Amp::UI.say "\tfrom #{err}" } exit end end |
#get_resource(resourceName, &aProc) ⇒ Object
73 74 75 76 |
# File 'lib/amp/dependencies/zip/ziprequire.rb', line 73 def get_resource(resourceName, &aProc) zl = ZipList.new($:.grep(/\.zip$/)) zl.get_input_stream(resourceName, &aProc) end |
#hook(names) { ... } ⇒ Object
Adds a hook to each of the provided hook entry points. Requires a block.
78 79 80 |
# File 'lib/amp/commands/hooks.rb', line 78 def hook(names, &block) Amp::Hook.new(names, &block) end |
#ignore_missing_files { ... } ⇒ Object
Allows any code called within the block to access non-existent files without raising an exception. Only “file not found” exceptions are ignored - all other exceptions will be raised as normal.
197 198 199 200 201 202 203 204 |
# File 'lib/amp/support/support.rb', line 197 def ignore_missing_files begin yield rescue Errno::ENOENT rescue StandardError raise end end |
#oldRequire ⇒ Object
56 |
# File 'lib/amp/dependencies/zip/ziprequire.rb', line 56 alias :oldRequire :require |
#require(moduleName) ⇒ Object
58 59 60 |
# File 'lib/amp/dependencies/zip/ziprequire.rb', line 58 def require(moduleName) zip_require(moduleName) || oldRequire(moduleName) end |
#ruby_19? ⇒ Boolean
2 |
# File 'lib/amp/support/ruby_19_compatibility.rb', line 2 def ruby_19?; (RUBY_VERSION >= "1.9"); end |
#zip_require(moduleName) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/amp/dependencies/zip/ziprequire.rb', line 62 def zip_require(moduleName) return false if already_loaded?(moduleName) get_resource(ensure_rb_extension(moduleName)) { |zis| eval(zis.read); $" << moduleName } return true rescue Errno::ENOENT => ex return false end |