Module: RequestLogAnalyzer::FileFormat

Defined in:
lib/request_log_analyzer/file_format.rb,
lib/request_log_analyzer/file_format/merb.rb,
lib/request_log_analyzer/file_format/rack.rb,
lib/request_log_analyzer/file_format/rails.rb,
lib/request_log_analyzer/file_format/apache.rb,
lib/request_log_analyzer/file_format/amazon_s3.rb,
lib/request_log_analyzer/file_format/rails_development.rb

Defined Under Namespace

Classes: AmazonS3, Apache, Base, Merb, Rack, Rails, RailsDevelopment

Class Method Summary collapse

Class Method Details

.const_missing(const) ⇒ Object



3
4
5
# File 'lib/request_log_analyzer/file_format.rb', line 3

def self.const_missing(const)
  RequestLogAnalyzer::load_default_class_file(self, const)
end

.load(file_format, *args) ⇒ Object

Loads a FileFormat::Base subclass instance. You can provide:

  • A FileFormat instance (which will return itself)

  • A FileFormat class (of which an imstance will be returned)

  • A filename (from which the FileFormat class is loaded)

  • A symbol of a built-in file format (e.g. :rails)



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
39
40
41
42
43
44
45
# File 'lib/request_log_analyzer/file_format.rb', line 13

def self.load(file_format, *args)
  klass = nil
  if file_format.kind_of?(RequestLogAnalyzer::FileFormat::Base)
    # this already is a file format! return itself
    return @current_file_format = file_format

  elsif file_format.kind_of?(Class) && file_format.ancestors.include?(RequestLogAnalyzer::FileFormat::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::FileFormat.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::FileFormat.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::FileFormat::Base)

  @current_file_format = klass.create(*args) # return an instance of the class
end