Class: StreamAuditor
- Inherits:
-
SoarAuditorApi::AuditorAPI
- Object
- SoarAuditorApi::AuditorAPI
- StreamAuditor
- Defined in:
- lib/stream_auditor.rb,
lib/stream_auditor/version.rb
Overview
An IO stream (or file) implementation of SoarAuditorApi::AuditorAPI
This implementation supports auditing to:
-
an already open IO object (or anything that implements IO#<< and IO#flush),
-
the standard error stream ($stderr),
-
the standard output stream ($stdout), or
-
a file.
Developers should not need to work directly with this class. Instead, they should configure it through the SOAR auditing provider.
Constant Summary collapse
- VERSION =
"1.0.2"
Instance Method Summary collapse
-
#audit(data) ⇒ Object
Write data to the configured stream.
-
#configuration_is_valid?(configuration) ⇒ true, false
Validates the configuration.
-
#configure(configuration = nil) ⇒ Object
Apply the configuration supplied to initialize.
Instance Method Details
#audit(data) ⇒ Object
Write data to the configured stream
The stream is immediately flushed after the data is written.
56 57 58 59 |
# File 'lib/stream_auditor.rb', line 56 def audit(data) stream << data.to_s.chomp + "\n" stream.flush end |
#configuration_is_valid?(configuration) ⇒ true, false
Validates the configuration
109 110 111 112 113 114 |
# File 'lib/stream_auditor.rb', line 109 def configuration_is_valid?(configuration) return false unless (configuration.keys - ["adaptor", "stream"]).empty? s = configuration["stream"] want_default_stream?(s) or want_stderr_stream?(s) or want_stdout_stream?(s) or want_io_stream?(s) or want_path_stream?(s) end |
#configure(configuration = nil) ⇒ Object
Apply the configuration supplied to initialize
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/stream_auditor.rb', line 86 def configure(configuration = nil) super if configuration s = configuration["stream"] @stream = if want_stdout_stream?(s) then $stdout elsif want_stderr_stream?(s) then $stderr elsif want_io_stream?(s) then s elsif want_path_stream?(s) then creative_open_file(s) end end end |