Class: Growl::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/growl/growl.rb

Overview

– Growl base ++

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Base

Initialize with optional block, which is then instance evaled or yielded depending on the blocks arity.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
# 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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



116
117
118
# File 'lib/growl/growl.rb', line 116

def args
  @args
end

Class Method Details

.switch(name) ⇒ Object

Define a switch name.

examples

switch :sticky

@growl.sticky!         # => true
@growl.sticky?         # => true
@growl.sticky = false  # => false
@growl.sticky?         # => false


164
165
166
167
168
169
170
# 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

.switchesObject

Return array of available switch symbols.



175
176
177
# File 'lib/growl/growl.rb', line 175

def self.switches
  @switches
end

Instance Method Details

#runObject

Run the notification, only –message is required.

Raises:



140
141
142
143
144
145
146
147
148
149
# 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