Sha256: 27ba75c2f899e137e57fe84d77ad4f8f86ff65ae344f8b1d71d617d4187b9ddb

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

module RequestLogAnalyzer::Spec::Matchers
  
  class HasLineDefinition
    
    def initialize(line_type)
      @line_type = line_type.to_sym
      @captures  = []
    end
      
    def capturing(*captures)
      @captures += captures
      return self
    end
    
    def matches?(file_format)
      if file_format.new.line_definitions.include?(@line_type)
        ld = file_format.new.line_definitions[@line_type]
        @captures.all? { |c| ld.captures.include?(c) }
      else
        false
      end
    end
  end
  
  class Parse
    def initialize(line)
      @line     = line
      @captures = nil
    end
    
    def failure_message
      message = "expected to parse the provided line"
      if @found_captures
        message << "with captures #{@captures.inspect}, but captured #{@found_captures.inspect}"
      end
      return message
    end
    
    def capturing(*captures)
      @captures = captures
      return self
    end
    
    def matches?(line_definition)
      hash = line_definition.matches(@line)
      if hash
        @found_captures = hash[:captures].to_a
        @captures.nil? ? true : @found_captures.eql?(@captures)
      else
        return false
      end
    end
  end
  
  def have_line_definition(line_type)
    return HasLineDefinition.new(line_type)
  end
  
  def parse(line)
    Parse.new(line)
  end
  
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
wvanbergen-request-log-analyzer-1.2.3 spec/lib/matchers.rb
wvanbergen-request-log-analyzer-1.2.4 spec/lib/matchers.rb
wvanbergen-request-log-analyzer-1.2.5 spec/lib/matchers.rb
wvanbergen-request-log-analyzer-1.2.6 spec/lib/matchers.rb
wvanbergen-request-log-analyzer-1.2.7 spec/lib/matchers.rb
request-log-analyzer-1.2.7 spec/lib/matchers.rb
request-log-analyzer-1.2.6 spec/lib/matchers.rb
request-log-analyzer-1.2.3 spec/lib/matchers.rb