Sha256: 41dea55638cb92e5afd3eeb2404e719a8f8d35c01552653e0a84352efb54dac6

Contents?: true

Size: 1.58 KB

Versions: 25

Compression:

Stored size: 1.58 KB

Contents

module Sys

  #
  # Trap signals!
  #
  # usage: trap("EXIT", "HUP", "ETC", :ignore=>["VTALRM"]) { |signal| puts "Got #{signal}!" }
  # (Execute Signal.list to see what's available.)
  #
  # No paramters defaults to all signals except VTALRM, CHLD, CLD, and EXIT.
  #
  def self.trap(*args, &block)
    options = if args.last.is_a?(Hash) then args.pop else Hash.new end
    args = [args].flatten
    signals = if args.any? then args else Signal.list.keys end

    ignore = %w[ VTALRM CHLD CLD EXIT ] unless ignore = options[:ignore]
    ignore = [ignore] unless ignore.is_a? Array

    signals = signals - ignore

    signals.each do |signal|
      p [:sig, signal]
      Signal.trap(signal) { yield signal }
    end
  end

  #-----------------------------------------------------------------------------

  cross_platform_method :browser_open

  #
  # Linux: Open an URL in the default browser (using "xdg-open").
  #
  def browser_open_linux(url)
    system("xdg-open", url)
  end

  #
  # Darwin: Open the webpage in a new chrome tab.
  #
  def browser_open_darwin(url)
    system("open", "-a", "chrome", url)
  end

  #-----------------------------------------------------------------------------

  def self.temperatures
    #/Applications/Utilities/TemperatureMonitor.app/Contents/MacOS/tempmonitor -a -l
    #CPU Core 1: 28 C
    #CPU Core 2: 28 C
    #SMART Disk Hitachi HTS543216L9SA02 (090831FBE200VCGH3D5F): 40 C
    #SMC CPU A DIODE: 41 C
    #SMC CPU A HEAT SINK: 42 C
    #SMC DRIVE BAY 1: 41 C
    #SMC NORTHBRIDGE POS 1: 46 C
    #SMC WLAN CARD: 45 C
    raise NotImplementedError.new("Sorry")
  end

end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
epitools-0.5.136 lib/epitools/sys/misc.rb
epitools-0.5.134 lib/epitools/sys/misc.rb
epitools-0.5.133 lib/epitools/sys/misc.rb
epitools-0.5.131 lib/epitools/sys/misc.rb
epitools-0.5.130 lib/epitools/sys/misc.rb
epitools-0.5.129 lib/epitools/sys/misc.rb
epitools-0.5.128 lib/epitools/sys/misc.rb
epitools-0.5.126 lib/epitools/sys/misc.rb
epitools-0.5.125 lib/epitools/sys/misc.rb
epitools-0.5.124 lib/epitools/sys/misc.rb
epitools-0.5.123 lib/epitools/sys/misc.rb
epitools-0.5.122 lib/epitools/sys/misc.rb
epitools-0.5.121 lib/epitools/sys/misc.rb
epitools-0.5.119 lib/epitools/sys/misc.rb
epitools-0.5.118 lib/epitools/sys/misc.rb
epitools-0.5.116 lib/epitools/sys/misc.rb
epitools-0.5.115 lib/epitools/sys/misc.rb
epitools-0.5.114 lib/epitools/sys/misc.rb
epitools-0.5.113 lib/epitools/sys/misc.rb
epitools-0.5.112 lib/epitools/sys/misc.rb