Class: Growl::Base
- Inherits:
-
Object
- Object
- Growl::Base
- Defined in:
- lib/growl/growl.rb
Overview
– Growl base ++
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Class Method Summary collapse
-
.switch(name) ⇒ Object
Define a switch
name. -
.switches ⇒ Object
Return array of available switch symbols.
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ Base
constructor
Initialize with optional
block, which is then instance evaled or yielded depending on the blocks arity. -
#run ⇒ Object
Run the notification, only –message is required.
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 = {}, &block @args = [] if block_given? if block.arity > 0 yield self else self.instance_eval &block end else .each do |key, value| send :"#{key}=", value end end end |
Instance Attribute Details
#args ⇒ Object (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 |
.switches ⇒ Object
Return array of available switch symbols.
175 176 177 |
# File 'lib/growl/growl.rb', line 175 def self.switches @switches end |
Instance Method Details
#run ⇒ Object
Run the notification, only –message is required.
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/growl/growl.rb', line 140 def run raise Error, 'message required' unless 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 |