Initialize with optional block
, which is then instance evaled
or yielded depending on the blocks arity.
# File lib/growl/growl.rb, line 122 def initialize options = {}, &block @args = [] if block_given? if block.arity > 0 yield self else self.instance_eval &block end else options.each do |key, value| send :"#{key}=", value end end end
Define a switch name
.
switch :sticky @growl.sticky! # => true @growl.sticky? # => true @growl.sticky = false # => false @growl.sticky? # => false
# File lib/growl/growl.rb, line 164 def self.switch name ivar = :"@#{name}" (@switches ||= []) << name attr_accessor :"#{name}" define_method(:"#{name}?") { instance_variable_get(ivar) } define_method(:"#{name}!") { instance_variable_set(ivar, true) } end
Return array of available switch symbols.
# File lib/growl/growl.rb, line 175 def self.switches @switches end
Run the notification, only –message is required.
# File lib/growl/growl.rb, line 140 def run raise Error, 'message required' unless message self.class.switches.each do |switch| if send(:"#{switch}?") args << "--#{switch}" args << send(switch).to_s if send(switch) && !(TrueClass === send(switch)) end end Growl.exec *args end