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)
-
+ (Object) load(file_format, *args)
Loads a Output::Base subclass instance.
Class Method Details
+ (Object) load(file_format, *args)
Loads a Output::Base subclass instance.
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 37 38 |
# File 'lib/request_log_analyzer/output.rb', line 5 def self.load(file_format, *args) klass = nil if file_format.kind_of?(RequestLogAnalyzer::Output::Base) # this already is a file format! return itself return file_format elsif file_format.kind_of?(Class) && file_format.ancestors.include?(RequestLogAnalyzer::Output::Base) # a usable class is provided. Use this format class. klass = file_format elsif file_format.kind_of?(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 raise "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 raise "Could not load a file format from #{file_format.inspect}" if klass.nil? raise "Invalid FileFormat class" unless klass.kind_of?(Class) && klass.ancestors.include?(RequestLogAnalyzer::Output::Base) klass.create(*args) # return an instance of the class end |