Class: Ape::Reporter

Inherits:
Erubis::Context
  • Object
show all
Includes:
Util
Defined in:
lib/ape/reporter.rb

Direct Known Subclasses

AtomReporter, HtmlReporter, TextReporter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

extended, included

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



7
8
9
# File 'lib/ape/reporter.rb', line 7

def debug
  @debug
end

#dialogsObject

Returns the value of attribute dialogs.



7
8
9
# File 'lib/ape/reporter.rb', line 7

def dialogs
  @dialogs
end

#dianumObject

Returns the value of attribute dianum.



7
8
9
# File 'lib/ape/reporter.rb', line 7

def dianum
  @dianum
end

#diarefsObject

Returns the value of attribute diarefs.



7
8
9
# File 'lib/ape/reporter.rb', line 7

def diarefs
  @diarefs
end

Returns the value of attribute footer.



7
8
9
# File 'lib/ape/reporter.rb', line 7

def footer
  @footer
end

#headerObject

Returns the value of attribute header.



7
8
9
# File 'lib/ape/reporter.rb', line 7

def header
  @header
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/ape/reporter.rb', line 7

def options
  @options
end

#serverObject

Returns the value of attribute server.



7
8
9
# File 'lib/ape/reporter.rb', line 7

def server
  @server
end

Class Method Details

.instance(key, opts = {}) ⇒ Object

Raises:

  • (StandardError)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ape/reporter.rb', line 13

def self.instance(key, opts = {})
  reporter = resolve_plugin(key, 'reporters', 'reporter')
  raise StandardError, "Unknown reporter: #{key}, outputs supported: #{supported_outputs}" unless reporter
  reporter.debug = opts.delete(:debug) || false
  reporter.server = opts.delete(:server) || false
  reporter.options = opts
  reporter.dialogs = {}
  reporter.diarefs = {}
  reporter.dianum = 1
  reporter
end

.supported_outputsObject



25
26
27
28
29
30
# File 'lib/ape/reporter.rb', line 25

def self.supported_outputs
  Dir[File.join(File.dirname(__FILE__), 'reporters/*.rb'),
      File.join(::Ape.home, 'reporters/*.rb')].map { |file|        
    file.gsub(/(.+\/reporters\/)(.+)(_reporter.rb)/, '\2').gsub(/_/, '')
  }.sort.join(", ").downcase
end

Instance Method Details

#add(*args) ⇒ Object

This method saves the messages that the validators send

=== Parameters
  * args[0] must be allways a reference to the validator.
  * args[1] should be the severity of the message, but it could be an array if several steps are recorded at once.
  * args[2] is the message to show.
  * args[3] is the message group key if it exits


39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ape/reporter.rb', line 39

def add(*args)
  if (args.length == 2 && args[1].kind_of?(Array))
    steps << args[1]
  elsif (args.length == 3)
    steps << {:severity => args[1], :message => args[2]}
  else
    steps << {:severity => :debug, :message => args[3]}
    show_crumbs(args[3]) if debug
    steps << {:severity => args[1], :message => args[2], :key => args[3]}        
  end
  puts "#{steps[-1][:severity].to_s.upcase}: #{steps[-1][:message]}" if debug && !steps[-1].kind_of?(Array)
end

#error(validator, message, crumb_key = nil) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/ape/reporter.rb', line 67

def error(validator, message, crumb_key=nil)
  unless crumb_key
    add(validator, :error, message)
  else
    add(validator, :error, message, crumb_key)
  end
end

#errorsObject



133
134
135
# File 'lib/ape/reporter.rb', line 133

def errors
  select(:error)
end

#info(validator, message) ⇒ Object



83
84
85
# File 'lib/ape/reporter.rb', line 83

def info(validator, message)
  add(validator, :info, message)
end

#infosObject



125
126
127
# File 'lib/ape/reporter.rb', line 125

def infos
  select(:info)
end

#line(output = STDOUT) ⇒ Object



95
96
97
98
# File 'lib/ape/reporter.rb', line 95

def line(output=STDOUT)     
  printf(output, "%2d. ", @lnum ||= 1)
  @lnum += 1
end

#list_item(message) ⇒ Object



91
92
93
# File 'lib/ape/reporter.rb', line 91

def list_item(message)
  steps[-1] << {:severity => :debug, :message => message}
end

#save_dialog(name, actor) ⇒ Object



100
101
102
# File 'lib/ape/reporter.rb', line 100

def save_dialog(name, actor)
  dialogs[name] = actor.crumbs
end

#security_warning(validator) ⇒ Object



52
53
54
55
56
57
# File 'lib/ape/reporter.rb', line 52

def security_warning(validator)
  unless (@sec_warning_writed)
    warning(validator, "Sending authentication information over an open channel is not a good security practice.", name)
    @sec_warning_writed = true
  end
end

#show_crumbs(key) ⇒ Object



104
105
106
107
108
# File 'lib/ape/reporter.rb', line 104

def show_crumbs(key)     
  dialogs[key].each do |d|
    puts "Dialog: #{d}"
  end      
end

#show_message(crumb, tf) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/ape/reporter.rb', line 110

def show_message(crumb, tf)
  message = crumb[1 .. -1]
  message.gsub!(/^\s*"/, '')
  message.gsub!(/"\s*$/, '')
  message.gsub!(/\\"/, '"')
  message = Escaper.escape message
  message.gsub!(/(\\r\\n|\\n|\\r)/, "\n<br/>")      
  message.gsub!(/\\t/, '&#xa0;&#xa0;&#xa0;&#xa0;')
  "<div class=\"#{tf.to_s}\">#{message}</div>"      
end

#start_list(validator, message) ⇒ Object



87
88
89
# File 'lib/ape/reporter.rb', line 87

def start_list(validator, message)
  add(validator, [ message + ":" ])
end

#stepsObject



9
10
11
# File 'lib/ape/reporter.rb', line 9

def steps
  @steps ||= []
end

#success(validator, message, crumb_key = nil) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/ape/reporter.rb', line 75

def success(validator, message, crumb_key=nil)
  unless crumb_key
    add(validator, :success, message)
  else
    add(validator, :success, message, crumb_key)
  end
end

#successesObject



121
122
123
# File 'lib/ape/reporter.rb', line 121

def successes
  select(:success)
end

#warning(validator, message, crumb_key = nil) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/ape/reporter.rb', line 59

def warning(validator, message, crumb_key=nil)
  unless crumb_key
    add(validator, :warning, message)
  else
    add(validator, :warning, message, crumb_key)
  end
end

#warningsObject



129
130
131
# File 'lib/ape/reporter.rb', line 129

def warnings
  select(:warning)
end