Class: Kawaii::Matcher Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/kawaii/matchers.rb

Overview

This class is abstract.

Base class for a route matcher.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) compile(path, options = {})

Creates a matcher. Generated matchers by default match only the beginning of the string containing the actual path from Rack environment.

Parameters:

  • path (String, Regexp, Matcher)

    path specification to compile to a matcher

  • options (Hash) (defaults to: {})

    :full_match to require the entire path to match the resulting matcher



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kawaii/matchers.rb', line 31

def self.compile(path, options = {})
  # @todo Make it extendable?
  matcher = if path.is_a?(String)
              StringMatcher.new(path)
            elsif path.is_a?(Regexp)
              RegexpMatcher.new(path)
            elsif path.is_a?(Matcher)
              path
            else
              fail RuntimeException, "#{path} is not a supported matcher"
            end
  options[:full_match] ? FullMatcher.new(matcher) : matcher
end

Instance Method Details

- (Match) match(_path)

Tries to match the actual path. no match.

Parameters:

  • _path (String)

    the actual path from Rack env

Returns:

  • (Match)

    if the beginning of path does match or nil if there is



49
50
51
# File 'lib/kawaii/matchers.rb', line 49

def match(_path)
  fail NotImplementedError
end