Parent

Rack::Mount::Strexp

Public Class Methods

compile(str, requirements = {}, separators = [], anchor = true) click to toggle source

Parses segmented string expression and converts it into a Regexp

  Strexp.compile('foo')
    # => %r{\Afoo\Z}

  Strexp.compile('foo/:bar', {}, ['/'])
    # => %r{\Afoo/(?<bar>[^/]+)\Z}

  Strexp.compile(':foo.example.com')
    # => %r{\A(?<foo>.+)\.example\.com\Z}

  Strexp.compile('foo/:bar', {:bar => /[a-z]+/}, ['/'])
    # => %r{\Afoo/(?<bar>[a-z]+)\Z}

  Strexp.compile('foo(.:extension)')
    # => %r{\Afoo(\.(?<extension>.+))?\Z}

  Strexp.compile('src/*files')
    # => %r{\Asrc/(?<files>.+)\Z}
    # File lib/rack/mount/strexp.rb, line 25
25:       def compile(str, requirements = {}, separators = [], anchor = true)
26:         return Regexp.compile(str) if str.is_a?(Regexp)
27: 
28:         requirements = requirements ? requirements.dup : {}
29:         normalize_requirements!(requirements, separators)
30: 
31:         parser = StrexpParser.new
32:         parser.anchor = anchor
33:         parser.requirements = requirements
34: 
35:         begin
36:           re = parser.scan_str(str)
37:         rescue Racc::ParseError => e
38:           raise RegexpError, e.message
39:         end
40: 
41:         Regexp.compile(re)
42:       end

Private Class Methods

normalize_requirements!(requirements, separators) click to toggle source
    # File lib/rack/mount/strexp.rb, line 46
46:         def normalize_requirements!(requirements, separators)
47:           requirements.each do |key, value|
48:             if value.is_a?(Regexp)
49:               if regexp_has_modifiers?(value)
50:                 requirements[key] = value
51:               else
52:                 requirements[key] = value.source
53:               end
54:             else
55:               requirements[key] = Regexp.escape(value)
56:             end
57:           end
58:           requirements.default ||= separators.any? ?
59:             "[^#{separators.join}]+" : '.+'
60:           requirements
61:         end
regexp_has_modifiers?(regexp) click to toggle source
    # File lib/rack/mount/strexp.rb, line 63
63:         def regexp_has_modifiers?(regexp)
64:           regexp.options & (Regexp::IGNORECASE | Regexp::EXTENDED) != 0
65:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.