Class: Rack::Mount::RegexpWithNamedGroups

Inherits:
Regexp
  • Object
show all
Defined in:
lib/rack/mount/regexp_with_named_groups.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regexp) ⇒ RegexpWithNamedGroups

Returns a new instance of RegexpWithNamedGroups.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rack/mount/regexp_with_named_groups.rb', line 17

def initialize(regexp)
  names = nil if names && !names.any?
  regexp, @names = Utils.extract_named_captures(regexp)

  @names = nil unless @names.any?

  if @names
    @named_captures = {}
    @names.each_with_index { |n, i| @named_captures[n] = [i+1] if n }
  end

  (@named_captures ||= {}).freeze
  (@names ||= []).freeze

  super(regexp)
end

Instance Attribute Details

#named_capturesObject (readonly)

Returns the value of attribute named_captures.



15
16
17
# File 'lib/rack/mount/regexp_with_named_groups.rb', line 15

def named_captures
  @named_captures
end

#namesObject (readonly)

Returns the value of attribute names.



15
16
17
# File 'lib/rack/mount/regexp_with_named_groups.rb', line 15

def names
  @names
end

Class Method Details

.new(regexp) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/rack/mount/regexp_with_named_groups.rb', line 7

def self.new(regexp)
  if regexp.is_a?(RegexpWithNamedGroups)
    regexp
  else
    super
  end
end