Module: RequestLogAnalyzer::Output
- Defined in:
- lib/request_log_analyzer/output.rb,
lib/request_log_analyzer/output/html.rb,
lib/request_log_analyzer/output/fixed_width.rb
Overview
Module for generating output
Defined Under Namespace
Classes: Base, FixedWidth, HTML
Class Method Summary collapse
-
.load(file_format, *args) ⇒ Object
Loads a Output::Base subclass instance.
Class Method Details
.load(file_format, *args) ⇒ Object
Loads a Output::Base subclass instance.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/request_log_analyzer/output.rb', line 4 def self.load(file_format, *args) klass = nil if file_format.is_a?(RequestLogAnalyzer::Output::Base) # this already is a file format! return itself return file_format elsif file_format.is_a?(Class) && file_format.ancestors.include?(RequestLogAnalyzer::Output::Base) # a usable class is provided. Use this format class. klass = file_format elsif file_format.is_a?(String) && File.exist?(file_format) # load a format from a ruby file require file_format const = RequestLogAnalyzer.to_camelcase(File.basename(file_format, '.rb')) if RequestLogAnalyzer::FileFormat.const_defined?(const) klass = RequestLogAnalyzer::Output.const_get(const) elsif Object.const_defined?(const) klass = Object.const_get(const) else fail "Cannot load class #{const} from #{file_format}!" end else # load a provided file format klass = RequestLogAnalyzer::Output.const_get(RequestLogAnalyzer.to_camelcase(file_format)) end # check the returned klass to see if it can be used fail "Could not load a file format from #{file_format.inspect}" if klass.nil? fail 'Invalid FileFormat class' unless klass.is_a?(Class) && klass.ancestors.include?(RequestLogAnalyzer::Output::Base) klass.create(*args) # return an instance of the class end |