Class: Rack::Mount::Strexp
- Inherits:
-
Regexp
- Object
- Regexp
- Rack::Mount::Strexp
- Defined in:
- lib/rack/mount/strexp.rb
Instance Method Summary collapse
-
#initialize(str, requirements = {}, separators = [], anchor = true) ⇒ Strexp
constructor
Parses segmented string expression and converts it into a Regexp.
Constructor Details
#initialize(str, requirements = {}, separators = [], anchor = true) ⇒ Strexp
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}
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rack/mount/strexp.rb', line 24 def initialize(str, requirements = {}, separators = [], anchor = true) return super(str) if str.is_a?(Regexp) requirements = requirements ? requirements.dup : {} normalize_requirements!(requirements, separators) parser = StrexpParser.new parser.anchor = anchor parser.requirements = requirements begin re = parser.scan_str(str) rescue Racc::ParseError => e raise RegexpError, e. end super(re) end |