Class: HttpRouter::Generator::PathGenerator

### Home Classes Methods

### In Files

- lib/http_router/generator.rb

### Parent

Object

### Methods

- ::new

### Files

- LICENSE

### Class/Module Index

Quicksearch

- HttpRouter
- HttpRouter::GenerationHelper
- HttpRouter::Generator
- HttpRouter::Generator::PathGenerator
- HttpRouter::Node
- HttpRouter::Node::AbstractRequestNode
- HttpRouter::Node::FreeRegex
- HttpRouter::Node::Glob
- HttpRouter::Node::GlobRegex
- HttpRouter::Node::Host
- HttpRouter::Node::Lookup
- HttpRouter::Node::Path
- HttpRouter::Node::Regex
- HttpRouter::Node::RequestMethod
- HttpRouter::Node::Root
- HttpRouter::Node::Scheme
- HttpRouter::Node::SpanningRegex
- HttpRouter::Node::UserAgent
- HttpRouter::Node::Variable
- HttpRouter::RegexRouteGeneration
- HttpRouter::Request
- HttpRouter::Response
- HttpRouter::Route
- HttpRouter::RouteHelper
- HttpRouter::Util

No matching classes.

# HttpRouter::Generator::PathGenerator

### Attributes

param_names[RW]
path[R]

### Public Class Methods

new(route, path, validation_regex = nil) click to toggle source

    # File lib/http_router/generator.rb, line 8
    def initialize(route, path, validation_regex = nil)
      @route = route
      @path = path.dup
      @param_names = []
      if path.is_a?(String)
        path[0, 0] = '/' unless path[0] == //
        regex_parts = path.split(/([:\*][a-zA-Z0-9_]+)/)
        regex, code = '', ''
        dynamic = false
        regex_parts.each_with_index do |part, index|
          case part[0]
          when ::, **
            if index != 0 && regex_parts[index - 1][-1] == \\\
              regex << Regexp.quote(part) unless validation_regex
              code << part
              dynamic = true
            else
              regex << (@route.matches_with(part[1, part.size].to_sym) || '.*?').to_s unless validation_regex
              code << "\#{args.shift || (options && options.delete(:#{part[1, part.size]})) || return}"
              dynamic = true
            end
          else
            regex << Regexp.quote(part) unless validation_regex
            code << part
          end
        end
        validation_regex ||= Regexp.new("^#{regex}$") if dynamic
        if validation_regex
          instance_eval             def generate(args, options)              generated_path = \"#{code}\"              #{validation_regex.inspect}.match(generated_path) ? URI.escape(generated_path) : nil            end, __FILE__, __LINE__ + 1
        else
          instance_eval             def generate(args, options)              URI.escape(\"#{code}\")            end, __FILE__, __LINE__ + 1
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.