Module: Sidekick::Actions::System
- Defined in:
- lib/sidekick/actions/system.rb
Instance Method Summary collapse
- #gem_load?(gemname) ⇒ Boolean
- #handling(err_kls = Exception, context = nil) ⇒ Object
- #needs(gem_name, reason) ⇒ Object
- #platform ⇒ Object
- #prefers(gem_name, reason) ⇒ Object
Instance Method Details
#gem_load?(gemname) ⇒ Boolean
17 18 19 20 21 22 |
# File 'lib/sidekick/actions/system.rb', line 17 def gem_load?(gemname) begin require gemname true rescue LoadError; false; end end |
#handling(err_kls = Exception, context = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sidekick/actions/system.rb', line 36 def handling(err_kls=Exception, context=nil) begin yield rescue err_kls => e if context notify "#{context}:\n#{e}", e.class.name else notify "#{e}\n#{e.backtrace[0..2]}", e.class.name end end end |
#needs(gem_name, reason) ⇒ Object
24 25 26 27 28 |
# File 'lib/sidekick/actions/system.rb', line 24 def needs(gem_name, reason) unless gem_load?(gem_name) abort "You must install the #{gem_name} gem #{reason}." end end |
#platform ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/sidekick/actions/system.rb', line 7 def platform { :linux => /linux/, :darwin => /darwin/, :windows => /mswin|mingw|cygwin/ }.each do |platform, regex| return platform if Config::CONFIG['host_os'] =~ regex end; :other end |
#prefers(gem_name, reason) ⇒ Object
30 31 32 33 34 |
# File 'lib/sidekick/actions/system.rb', line 30 def prefers(gem_name, reason) unless gem_load?(gem_name) log "Please install the #{gem_name} gem #{reason}." end end |