Class: HttpRouter::Glob

Inherits:
Variable show all
Defined in:
lib/http_router/glob.rb

Instance Attribute Summary

Attributes inherited from Variable

#matches_with, #name

Instance Method Summary collapse

Methods inherited from Variable

#===, #initialize

Constructor Details

This class inherits a constructor from HttpRouter::Variable

Instance Method Details

#consume(parts, whole_path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/http_router/glob.rb', line 7

def consume(parts, whole_path)
  if @matches_with
    params = [parts.shift]
    params << parts.shift while matches?(parts, whole_path)
    params
  else
    params = parts.dup
    parts.clear
    params
  end
end

#matches?(parts, whole_path) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/http_router/glob.rb', line 3

def matches?(parts, whole_path)
  @matches_with.nil? or (!parts.empty? and match = @matches_with.match(parts.first) and match.begin(0))
end