Class: Aruba::Platforms::Announcer

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/platforms/announcer.rb

Overview

Announcer

Examples:

Activate your you own channel in cucumber


Before('@announce-my-channel') do
  aruba.announcer.activate :my_channel
end

Activate your you own channel in rspec > 3


before do
  current_example = context.example
  aruba.announcer.activate :my_channel if current_example.[:announce_my_channel]
end

Aruba.announcer.announce(:my_channel, 'my message')

Defined Under Namespace

Classes: BaseAnnouncer, KernelPutsAnnouncer, PutsAnnouncer

Instance Method Summary collapse

Constructor Details

#initializeAnnouncer

Returns a new instance of Announcer.


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/aruba/platforms/announcer.rb', line 65

def initialize
  @announcers = []
  @announcers << PutsAnnouncer.new
  @announcers << KernelPutsAnnouncer.new

  @colorizer = Aruba::Colorizer.new

  @announcer         = @announcers.first
  @channels          = {}
  @output_formats    = {}

  after_init
end

Instance Method Details

#activate(*chns) ⇒ Object

Activate a channel

Parameters:

  • chns (Symbol)

    The name of the channel to activate


146
147
148
149
150
# File 'lib/aruba/platforms/announcer.rb', line 146

def activate(*chns)
  chns.flatten.each { |c| channels[c.to_sym] = true }

  self
end

#activated?(channel) ⇒ Boolean

Check if channel is activated

Parameters:

  • channel (Symbol)

    The name of the channel to check

Returns:

  • (Boolean)

138
139
140
# File 'lib/aruba/platforms/announcer.rb', line 138

def activated?(channel)
  channels[channel.to_sym] == true
end

#announce(channel, *args) { ... } ⇒ Object

Announce information to channel

Parameters:

  • channel (Symbol)

    The name of the channel to check

  • args (Array)

    Arguments

Yields:

  • If block is given, that one is called and the return value is used as message to be announced.


163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/aruba/platforms/announcer.rb', line 163

def announce(channel, *args)
  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

#modeSymbol

Fecth mode of announcer

Returns:

  • (Symbol)

    The current announcer mode


130
131
132
# File 'lib/aruba/platforms/announcer.rb', line 130

def mode
  @announcer.mode
end

#mode=(m) ⇒ Object

Change mode of announcer

Parameters:

  • m (Symbol)

    The mode to set


121
122
123
124
125
# File 'lib/aruba/platforms/announcer.rb', line 121

def mode=(m)
  @announcer = @announcers.find { |a| a.mode? m.to_sym }

  self
end

#resetObject

Reset announcer


113
114
115
# File 'lib/aruba/platforms/announcer.rb', line 113

def reset
  @announcer = @announcers.first
end