Class: Requirer
Class Method Summary collapse
- .extract_gem_from_exception(txt) ⇒ Object
- .require_classes(files) ⇒ Object
- .require_gem(name, options = {}) ⇒ Object
- .show(txt) ⇒ Object
Class Method Details
.extract_gem_from_exception(txt) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/xiki/requirer.rb', line 25 def self.extract_gem_from_exception txt txt = txt[/-- (.*)/, 1] || txt[/RubyGem (.*)/, 1] || txt[/Could not find (.+?) /, 1] || txt return nil if ! txt txt.sub!(/\(.+/, '') txt.strip end |
.require_classes(files) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/xiki/requirer.rb', line 34 def self.require_classes files files.each do |l| begin require l rescue LoadError => e self.show "#{e.to_s}\n" gem_name = self.extract_gem_from_exception e.to_s self.show "Xiki requires the '#{gem_name}' gem.\n% gem install #{gem_name}\n\n" end end end |
.require_gem(name, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/xiki/requirer.rb', line 15 def self.require_gem name, ={} begin gem name require [:name2] || name rescue Exception=>e self.show "Xiki #{[:optional] ? 'optionally uses' : 'requires'} the '#{name}' gem.\n% gem install #{name}\n\n" raise e if [:raise] end end |
.show(txt) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/xiki/requirer.rb', line 4 def self.show txt if ! $el return if txt !~ /(^Xiki requires|exception:$)/ return puts "#{txt}" end $el.switch_to_buffer "Issues Loading Xiki" $el.insert txt $el.bury_buffer unless $el.buffer_substring($el.point_min, $el.point_max) =~ /(^Xiki requires|exception:$)/ end |