Module: Rack::Mount::GeneratableRegexp::InstanceMethods

### Home Classes Methods

### In Files

- lib/rack/mount/generatable_regexp.rb

### Methods

- ::extended
- #captures
- #defaults
- #defaults=
- #freeze
- #generatable?
- #generate
- #required_captures
- #required_defaults
- #required_params
- #segments

### 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::GeneratableRegexp::InstanceMethods

### Constants

EMPTY_STRING

### Public Class Methods

extended(obj) click to toggle source

    # File lib/rack/mount/generatable_regexp.rb, line 31
    def self.extended(obj)
      obj.segments
    end

### Public Instance Methods

captures() click to toggle source

    # File lib/rack/mount/generatable_regexp.rb, line 72
    def captures
      segments.flatten.find_all { |s| s.is_a?(DynamicSegment) }
    end

defaults() click to toggle source

    # File lib/rack/mount/generatable_regexp.rb, line 42
    def defaults
      @defaults ||= {}
    end

defaults=(defaults) click to toggle source

    # File lib/rack/mount/generatable_regexp.rb, line 35
    def defaults=(defaults)
      @required_captures = nil
      @required_params = nil
      @required_defaults = nil
      @defaults = defaults
    end

freeze() click to toggle source

    # File lib/rack/mount/generatable_regexp.rb, line 96
    def freeze
      segments
      captures
      required_captures
      required_params
      required_defaults
      super
    end

generatable?() click to toggle source

    # File lib/rack/mount/generatable_regexp.rb, line 46
    def generatable?
      segments.any?
    end

generate(params = {}, recall = {}, options = {}) click to toggle source

    # File lib/rack/mount/generatable_regexp.rb, line 50
    def generate(params = {}, recall = {}, options = {})
      return nil unless generatable?

      merged = recall.merge(params)
      return nil unless required_params.all? { |p| merged.include?(p) }
      return nil unless required_defaults.all? { |k, v| merged[k] == v }

      generate_from_segments(segments, params, merged, options)
    end

required_captures() click to toggle source

    # File lib/rack/mount/generatable_regexp.rb, line 76
    def required_captures
      @required_captures ||= segments.find_all { |s|
        s.is_a?(DynamicSegment) && !@defaults.include?(s.name)
      }.freeze
    end

required_defaults() click to toggle source

    # File lib/rack/mount/generatable_regexp.rb, line 86
    def required_defaults
      @required_defaults ||= begin
        required_defaults = @defaults.dup
        captures.inject({}) { |h, s| h.merge!(s.to_hash) }.keys.each { |name|
          required_defaults.delete(name)
        }
        required_defaults
      end
    end

required_params() click to toggle source

    # File lib/rack/mount/generatable_regexp.rb, line 82
    def required_params
      @required_params ||= required_captures.map { |s| s.name }.freeze
    end

segments() click to toggle source

    # File lib/rack/mount/generatable_regexp.rb, line 60
    def segments
      @segments ||= begin
        defaults
        segments = []
        catch(:halt) do
          expression = Utils.parse_regexp(self)
          segments = parse_segments(expression)
        end
        segments
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.