Class: Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptest-publisher/formatters/reporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(listeners = nil) ⇒ Reporter

Returns a new instance of Reporter.



2
3
4
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 2

def initialize(listeners = nil)
  @listeners = listeners || []
end

Instance Method Details

#add_listener(listener) ⇒ Object



6
7
8
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 6

def add_listener(listener)
  @listeners << listener
end

#ask(question) ⇒ Object



60
61
62
63
64
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 60

def ask(question)
  askable_listener = @listeners.find { |l| l.respond_to?(:ask) }
  return nil if askable_listener.nil?
  return askable_listener.ask(question)
end

#dump_error(error, message = nil) ⇒ Object



10
11
12
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 10

def dump_error(error, message = nil)
  notify(:dump_error, error, message)
end

#failure_message(message) ⇒ Object



49
50
51
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 49

def failure_message(message)
  notify(:show_status_message, message, :failure)
end

#notify(message, *args) ⇒ Object



53
54
55
56
57
58
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 53

def notify(message, *args)
  @listeners.each do |listener|
    listener.send(message, *args)
  end
  nil
end

#show_error(message) ⇒ Object



14
15
16
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 14

def show_error(message)
  notify(:show_error, message)
end

#show_failure(message) ⇒ Object



18
19
20
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 18

def show_failure(message)
  notify(:show_failure, message)
end

#show_options(options, message = nil) ⇒ Object



22
23
24
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 22

def show_options(options, message = nil)
  notify(:show_options, options, message)
end

#show_verbose_message(message) ⇒ Object



26
27
28
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 26

def show_verbose_message(message)
  notify(:show_verbose_message, message)
end

#success_message(message) ⇒ Object



41
42
43
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 41

def success_message(message)
  notify(:show_status_message, message, :success)
end

#warning_message(message) ⇒ Object



45
46
47
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 45

def warning_message(message)
  notify(:show_status_message, message, :warning)
end

#with_status_message(message, &blk) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/hiptest-publisher/formatters/reporter.rb', line 30

def with_status_message(message, &blk)
  notify(:show_status_message, message)
  status = :success
  yield
rescue
  status = :failure
  raise
ensure
  notify(:show_status_message, message, status)
end