Sha256: 093066256fdf235687211d70a36ec643f4c823b912469891e361130b084fe3bc

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

module Rerun
  module System

    def mac?
      # puts "RUBY_PLATFORM=#{RUBY_PLATFORM}"
      RUBY_PLATFORM =~ /darwin/i
    end

    def osx_foundation?
      mac? and begin
        if $osx_foundation.nil?
          require 'osx/foundation'
          OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
          $osx_foundation = true
        end
        $osx_foundation
      rescue LoadError
        $osx_foundation = false
      end
    end

    def windows?
       RUBY_PLATFORM =~ /mswin/i
    end

    def linux?
       RUBY_PLATFORM =~ /linux/i
    end

    # do we have growl or not?
    def growl?
      mac? && (growlcmd != "")
    end

    def growlcmd
      `which growlnotify`.chomp
    end

    def app_name
      # todo: make sure this works in non-Mac and non-Unix environments
      File.expand_path(".").gsub(/^.*\//, '').capitalize
    end

    def icon
      libdir = "#{File.expand_path(File.dirname(File.dirname(__FILE__)))}/lib"
      $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)

      rails_sig_file = File.expand_path(".")+"/config/boot.rb"
      return "#{libdir}/../icons/rails_red_sml.png" if File.exists? rails_sig_file
      return nil
    end

    def growl(title, body, background = true)
      if growl?
        icon_str = ("--image \"#{icon}\"" if icon)
        s = "#{growlcmd} -n \"#{app_name}\" -m \"#{body}\" \"#{app_name} #{title}\" #{icon_str}"
        s += " &" if background
        `#{s}`
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rerun-0.6.6 lib/rerun/system.rb
rerun-0.6.5 lib/rerun/system.rb
rerun-0.6.4 lib/rerun/system.rb
rerun-0.6.3 lib/rerun/system.rb
rerun-0.6.2 lib/rerun/system.rb