PRagger:notify_growlを書いてみた
書いてみたのはよいが,PRaggerの最新版が短くなりすぎててビビった.Configクラスとか消したんだ!やっぱgemを素直にrequireできないのは不都合なのかな?お陰で,notify_growlも最新版対応するともう少し簡単になりそうってことで,ちょっと修正,今に至る.
必要なもの
def notify_growl(config, data) require 'rubygems' begin require 'ruby-growl' rescue LoadError puts <<LERR LoadError: Please install gem "ruby-growl" # gem install ruby-growl LERR exit end default_setting = { :host => "localhost", # host to connect :app_name => "PRagger", # name of the application :password => nil, # needed to send notifications to host :title => "PRagger", # title for notification :sticky => false, # makes the notification stick until clicked :jp => false # notify in Japanese (default English) } default_setting.each do |k, v| unless config[k] config[k] = v end end if data.size > 0 g = Growl.new(config[:host], config[:app_name], ["notify-growl"], nil, config[:password]) if config[:jp] message = "#{data.size}件の新着フィードがあります" else message = "#{data.size} new feeds available" end begin g.notify("notify_growl", config[:title], message, 0, config[:sticky]) rescue puts <<NOGROWL Error: Please install or start Growl http://growl.info/ NOGROWL exit end end return data end
思ったんだけど,もうPRagger本体でrubygemsぐらいはrequireしといて損は無いかもね.ちなみに,ソースコード中の英文は適当.