@private
@example Activate your you own channel in cucumber
Before('@announce-my-channel') do aruba.announcer.activate :my_channel end
@example Activate your you own channel in rspec > 3
before do current_example = context.example aruba.announcer.activate :my_channel if current_example.metadata[:announce_my_channel] end Aruba.announcer.announce(:my_channel, 'my message')
# 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
Activate a channel
@param [Symbol] channel
The name of the channel to activate
# File lib/aruba/platforms/announcer.rb, line 159 def activate(*chns) chns.flatten.each { |c| channels[c.to_sym] = true } self end
Check if channel is activated
@param [Symbol] channel
The name of the channel to check
# File lib/aruba/platforms/announcer.rb, line 151 def activated?(channel) channels[channel.to_sym] == true end
Announce information to channel
@param [Symbol] channel
The name of the channel to check
@param [Array] args
Arguments
@yield
If block is given, that one is called and the return value is used as message to be announced.
# 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) message = if block_given? the_output_format.call(yield) else the_output_format.call(*args) end message += "\n" message = colorizer.cyan(message) announcer.announce(message) nil end
@deprecated
# 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
@deprecated
# 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
@deprecated
# 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
Change mode of announcer
@param [Symbol] m
The mode to set
# File lib/aruba/platforms/announcer.rb, line 141 def mode=(m) @announcer = @announcers.find { |a| f.mode? m.to_sym } self end
Reset announcer
# File lib/aruba/platforms/announcer.rb, line 133 def reset @announcer = @announcers.first end
@deprecated
# 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
@deprecated
# 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