Class: Journey::Formatter

### Home Classes Methods

### In Files

- lib/journey/formatter.rb

### Parent

Object

### Methods

- ::new
- #clear
- #generate

### Files

- CHANGELOG.rdoc
- Manifest.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Journey
- Journey::Formatter
- Journey::GTG
- Journey::GTG::Builder
- Journey::GTG::MatchData
- Journey::GTG::Simulator
- Journey::GTG::TransitionTable
- Journey::NFA
- Journey::NFA::Builder
- Journey::NFA::MatchData
- Journey::NFA::Simulator
- Journey::NFA::TransitionTable
- Journey::NFA::Visitor
- Journey::Nodes
- Journey::Nodes::Binary
- Journey::Nodes::Cat
- Journey::Nodes::Dummy
- Journey::Nodes::Group
- Journey::Nodes::Literal
- Journey::Nodes::Or
- Journey::Nodes::Star
- Journey::Nodes::Symbol
- Journey::Nodes::Terminal
- Journey::Nodes::Unary
- Journey::Parser
- Journey::Path
- Journey::Path::Pattern
- Journey::Path::Pattern::MatchData
- Journey::Route
- Journey::Router
- Journey::Router::RoutingError
- Journey::Router::Strexp
- Journey::Router::Utils
- Journey::Router::Utils::UriEscape
- Journey::Routes
- Journey::Scanner
- Rack

No matching classes.

# Journey::Formatter

The Formatter class is used for formatting URLs. For example, parameters passed to `url_for` in rails will eventually call Formatter#generate

### Attributes

routes[R]

### Public Class Methods

new(routes) click to toggle source

    # File lib/journey/formatter.rb, line 8
    def initialize routes
      @routes = routes
      @cache  = nil
    end

### Public Instance Methods

clear() click to toggle source

    # File lib/journey/formatter.rb, line 49
    def clear
      @cache = nil
    end

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

    # File lib/journey/formatter.rb, line 13
    def generate key, name, options, recall = {}, parameterize = nil
      constraints = recall.merge options

      match_route(name, constraints) do |route|
        data = constraints.dup

        keys_to_keep = route.parts.reverse.drop_while { |part|
          !options.key?(part) || (options[part] || recall[part]).nil?
        } | route.required_parts

        (data.keys - keys_to_keep).each do |bad_key|
          data.delete bad_key
        end

        parameterized_parts = data.dup

        if parameterize
          parameterized_parts.each do |k,v|
            parameterized_parts[k] = parameterize.call(k, v)
          end
        end

        parameterized_parts.keep_if { |_,v| v  }

        next if !name && route.requirements.empty? && route.parts.empty?

        next unless verify_required_parts!(route, parameterized_parts)

        z = Hash[options.to_a - data.to_a - route.defaults.to_a]

        return [route.format(parameterized_parts), z]
      end

      raise Router::RoutingError
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.