LoginSignup
3
3

More than 5 years have passed since last update.

uuid gem って酷くない?

Posted at

別に uuid gem を使いたかったわけではないけど、はまったので恨み節 (--;

class Growl
  def initialize(ip, name = 'ruby-growl')
    @g = ::Growl::GNTP.new ip, name
    @g.add_notification "notification", "#{name}", FAX::FAX_LOGO_PNG
  end

  def notify(title, message, url)
    begin
      @g.notify "notification", title, message, 0, true, nil, url
    rescue Growl::GNTP::UnknownApplication
      @g.register
      retry
    end
  end
end

このコードで Linux の /etc/crontab から定期的に Growl の通知を行うようなスクリプトを実行したところ、意味不明な以下のメッセージに悩まされた。

rake aborted!
Permission denied - /.ruby-uuid

「.ruby-uuid って何だ?」と思って lib/ruby/ 以下で find したところ、uuid gem の lib/uuid.rb の self.state_file メソッド中に以下のコードが (--;

    begin
      require 'Win32API'
     (省略)
    rescue LoadError
      state_dir = Dir.tmpdir
    end

    @state_file = File.join(state_dir, 'ruby-uuid')

これ、Windows 環境以外だと、特定のアカウント権限でのみ実行している場合には良いけど、複数アカウントで ruby-growl 使ったスクリプトを動かすとおかしなことになるんでは…

とりあえず

require 'uuid'

class Growl
  def initialize(ip, name = 'ruby-growl')
    UUID.state_file = false
    @g = ::Growl::GNTP.new ip, name
    @g.add_notification "notification", "#{name}", FAX::FAX_LOGO_PNG
  end

と UUID.state_file = false することで回避できたので、細かくは追っかけていない。気が向いたらもうチョイ、コードを読むけど、誰か分かる人がいたら本家にパッチでも送ってあげて欲しい。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3