Class: Aruba::Platforms::Announcer
- Inherits:
-
Object
- Object
- Aruba::Platforms::Announcer
- Defined in:
- lib/aruba/platforms/announcer.rb
Overview
Announcer
Defined Under Namespace
Classes: KernelPutsAnnouncer, PutsAnnouncer
Instance Method Summary collapse
-
#activate(*chns) ⇒ Object
Activate a channel.
-
#activated?(channel) ⇒ Boolean
Check if channel is activated.
-
#announce(channel, *args) { ... } ⇒ Object
Announce information to channel.
- #cmd(cmd) ⇒ Object deprecated Deprecated.
- #dir(dir) ⇒ Object deprecated Deprecated.
- #env(name, value) ⇒ Object deprecated Deprecated.
-
#initialize(*args) ⇒ Announcer
constructor
A new instance of Announcer.
-
#mode=(m) ⇒ Object
Change mode of announcer.
-
#reset ⇒ Object
Reset announcer.
- #stderr(content) ⇒ Object deprecated Deprecated.
- #stdout(content) ⇒ Object deprecated Deprecated.
Constructor Details
#initialize(*args) ⇒ Announcer
Returns a new instance of Announcer.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/aruba/platforms/announcer.rb', line 58 def initialize(*args) @announcers = [] @announcers << PutsAnnouncer.new @announcers << KernelPutsAnnouncer.new @colorizer = Aruba::Colorizer.new @announcer = @announcers.first @channels = {} @output_formats = {} @options = args[1] || {} after_init end |
Instance Method Details
#activate(*chns) ⇒ Object
Activate a channel
159 160 161 162 163 |
# File 'lib/aruba/platforms/announcer.rb', line 159 def activate(*chns) chns.flatten.each { |c| channels[c.to_sym] = true } self end |
#activated?(channel) ⇒ Boolean
Check if channel is activated
151 152 153 |
# File 'lib/aruba/platforms/announcer.rb', line 151 def activated?(channel) channels[channel.to_sym] == true end |
#announce(channel, *args) { ... } ⇒ Object
Announce information to channel
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/aruba/platforms/announcer.rb', line 176 def announce(channel, *args, &block) channel = channel.to_sym the_output_format = if output_formats.key? channel output_formats[channel] else proc { |v| format('%s', v) } end return unless activated?(channel) = if block_given? the_output_format.call(yield) else the_output_format.call(*args) end += "\n" = colorizer.cyan() announcer.announce() nil end |
#cmd(cmd) ⇒ Object
Deprecated.
219 220 221 222 |
# File 'lib/aruba/platforms/announcer.rb', line 219 def cmd(cmd) warn('The announcer now has a new api to activate channels. Please use this one announce(:command, message)') announce :command, cmd end |
#dir(dir) ⇒ Object
Deprecated.
213 214 215 216 |
# File 'lib/aruba/platforms/announcer.rb', line 213 def dir(dir) warn('The announcer now has a new api to activate channels. Please use this one announce(:directory, message)') announce :directory, dir end |
#env(name, value) ⇒ Object
Deprecated.
225 226 227 228 229 |
# File 'lib/aruba/platforms/announcer.rb', line 225 def env(name, value) warn('The announcer now has a new api to activate channels. Please use this one: announce(:changed_environment, key, value)') announce :changed_environment, name, value end |
#mode=(m) ⇒ Object
Change mode of announcer
141 142 143 144 145 |
# File 'lib/aruba/platforms/announcer.rb', line 141 def mode=(m) @announcer = @announcers.find { |a| f.mode? m.to_sym } self end |
#reset ⇒ Object
Reset announcer
133 134 135 |
# File 'lib/aruba/platforms/announcer.rb', line 133 def reset @announcer = @announcers.first end |
#stderr(content) ⇒ Object
Deprecated.
207 208 209 210 |
# File 'lib/aruba/platforms/announcer.rb', line 207 def stderr(content) warn('The announcer now has a new api to activate channels. Please use this one: announce(:stderr, message)') announce :stderr, content end |
#stdout(content) ⇒ Object
Deprecated.
201 202 203 204 |
# File 'lib/aruba/platforms/announcer.rb', line 201 def stdout(content) warn('The announcer now has a new api to activate channels. Please use this one: announce(:stdout, message)') announce :stdout, content end |