Class: Rack::Mount::Strexp

### Home Classes Methods

### In Files

- lib/rack/mount/strexp.rb

### Parent

Object

### Methods

- ::compile
- ::new

### Class/Module Index

Quicksearch

- Rack
- Rack::Mount
- Rack::Mount::Analysis
- Rack::Mount::Analysis::Splitting
- Rack::Mount::Analysis::Splitting::Key
- Rack::Mount::GeneratableRegexp
- Rack::Mount::GeneratableRegexp::InstanceMethods
- Rack::Mount::RegexpWithNamedGroups
- Rack::Mount::Route
- Rack::Mount::RouteSet
- Rack::Mount::RoutingError
- Rack::Mount::Strexp
- Rack::Mount::StrexpParser
- Rack::Mount::StrexpParser::ScanError
- Rack::Mount::Utils
- Regin
- Regin::Alternation
- Regin::Anchor
- Regin::Atom
- Regin::Character
- Regin::CharacterClass
- Regin::Collection
- Regin::Expression
- Regin::Group
- Regin::Options
- Regin::Parser
- Regin::Parser::ScanError

No matching classes.

# 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
    def compile(str, requirements = {}, separators = [], anchor = true)
      return Regexp.compile(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.message
      end

      Regexp.compile(re)
    end

Also aliased as: new
new(str, requirements = {}, separators = [], anchor = true) click to toggle source
Alias for: compile

[Validate]

Generated with the Darkfish Rdoc Generator 2.