class Growl::Base

Attributes

args[R]

Public Class Methods

new(options = {}) { |self| ... } click to toggle source

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
switch(name) click to toggle source

Define a switch name.

examples

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
switches() click to toggle source

Return array of available switch symbols.

# File lib/growl/growl.rb, line 175
def self.switches
  @switches
end

Public Instance Methods

run() click to toggle source

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