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
  if current_example.[:announce_my_channel]
    aruba.announcer.activate :my_channel
  end
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.



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

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



158
159
160
161
162
# File 'lib/aruba/platforms/announcer.rb', line 158

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)


150
151
152
# File 'lib/aruba/platforms/announcer.rb', line 150

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.



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/aruba/platforms/announcer.rb', line 175

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)

  begin
    if block_given?
      value = yield
      args << value
    end

    message = the_output_format.call(*args)
    message += "\n"
    message = colorizer.cyan(message)
  rescue NotImplementedError => e
    message = "Error fetching announced value for #{channel}: #{e.message}"
  end

  announcer.announce(message)

  nil
end

#modeSymbol

Fecth mode of announcer

Returns:

  • (Symbol)

    The current announcer mode



142
143
144
# File 'lib/aruba/platforms/announcer.rb', line 142

def mode
  @announcer.mode
end

#mode=(m) ⇒ Object

Change mode of announcer

Parameters:

  • m (Symbol)

    The mode to set



135
136
137
# File 'lib/aruba/platforms/announcer.rb', line 135

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

#resetObject

Reset announcer



127
128
129
# File 'lib/aruba/platforms/announcer.rb', line 127

def reset
  @announcer = @announcers.first
end