Class: RightScale::AuditFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/right_agent/audit_formatter.rb

Overview

Standard formatter for audit entries Each method return a hash of two elements:

- :summary contains the updated summary of the audit entry
- :detail contains the details to be appended to the audit entry

Class Method Summary collapse

Class Method Details

.error(text) ⇒ Object

Append error text to current audit section

Parameters

text(String)

Error message to be appended

Return

entry(Hash)

Hash containing new audit entry detail



84
85
86
# File 'lib/right_agent/audit_formatter.rb', line 84

def self.error(text)
  entry = { :detail => "*ERROR> #{text}\n" }
end

.info(text) ⇒ Object

Append info text to current audit section

Parameters

info(String)

Information to be appended

Return

entry(Hash)

Hash containing new audit entry detail



73
74
75
# File 'lib/right_agent/audit_formatter.rb', line 73

def self.info(text)
  entry = { :detail => wrap_text(text) }
end

.new_section(title) ⇒ Object

Start new audit section

Parameters

title(String)

New section title

Return

entry(Hash)

Hash containing new audit entry summary and detail



38
39
40
41
# File 'lib/right_agent/audit_formatter.rb', line 38

def self.new_section(title)
  title = '' unless title
  entry = { :summary => title, :detail => "#{ '****' * 20 }\n*RS>#{ title.center(72) }****\n" }
end

.output(text) ⇒ Object

Append output to current audit section

Parameters

text(String)

Output to be appended

Return

entry(Hash)

Hash containing new audit entry detail



61
62
63
64
# File 'lib/right_agent/audit_formatter.rb', line 61

def self.output(text)
  text += "\n" unless text[-1, 1] == "\n"
  entry = { :detail => text }
end

.status(status) ⇒ Object

Update audit summary

Parameters

status(String)

Updated audit status

Return

entry(Hash)

Hash containing new audit entry summary and detail



50
51
52
# File 'lib/right_agent/audit_formatter.rb', line 50

def self.status(status)
  entry = { :summary => status, :detail => wrap_text(status) }
end

.wrap_text(txt, prefix = '*RS> ', col = 80) ⇒ Object

Wrap text to given number of columns Tries to be smart and only wrap when there is a space

Parameters

txt(String)

Text to be wrapped

prefix(String>

Prefix for each wrapped line, default to ‘*RS) ’

col(Integer)

Maximum number of columns for each line, default to 80

Return

wrapped_text(String)

Wrapped text



100
101
102
103
# File 'lib/right_agent/audit_formatter.rb', line 100

def self.wrap_text(txt, prefix = '*RS> ', col = 80)
  txt = '' unless txt
  wrapped_text = txt.gsub(/(.{1,#{col - prefix.size}})( +|$\n?)|(.{1,#{col - prefix.size}})/, "#{prefix}\\1\\3\n").rstrip + "\n"     
end