Class: Lydia::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/lydia/route.rb

Constant Summary collapse

WILDCARD_REGEX =
%r{\/\*(.*)}
NAMED_SEGMENTS_REGEX =
%r{\/([^\/]*):([^:$\/]+)}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_method, namespace, pattern, options = {}, &block) ⇒ Route

Returns a new instance of Route.



8
9
10
11
12
13
14
15
# File 'lib/lydia/route.rb', line 8

def initialize(request_method, namespace, pattern, options = {}, &block)
  @request_method = request_method
  @namespace = namespace
  @pattern = pattern
  @options = options
  @block = block
  @regexp = init_regexp
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/lydia/route.rb', line 3

def block
  @block
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



3
4
5
# File 'lib/lydia/route.rb', line 3

def namespace
  @namespace
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/lydia/route.rb', line 3

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/lydia/route.rb', line 3

def params
  @params
end

#patternObject (readonly)

Returns the value of attribute pattern.



3
4
5
# File 'lib/lydia/route.rb', line 3

def pattern
  @pattern
end

#regexpObject (readonly)

Returns the value of attribute regexp.



3
4
5
# File 'lib/lydia/route.rb', line 3

def regexp
  @regexp
end

#request_methodObject (readonly)

Returns the value of attribute request_method.



3
4
5
# File 'lib/lydia/route.rb', line 3

def request_method
  @request_method
end

Instance Method Details

#match?(env) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/lydia/route.rb', line 17

def match?(env)
  match = @regexp.match((env['PATH_INFO']).to_s)
  if match && match.names.size
    @params = Hash[match.names.map(&:to_sym).zip(match.captures)]
  end
  match
end