module Roda::RodaPlugins::PathRewriter::ClassMethods

  1. lib/roda/plugins/path_rewriter.rb

Methods

Public Instance

  1. freeze
  2. rewrite_path

Public Instance methods

freeze()

Freeze the path rewrite metadata.

[show source]
   # File lib/roda/plugins/path_rewriter.rb
57 def freeze
58   opts[:remaining_path_rewrites].freeze
59   opts[:path_info_rewrites].freeze
60   super
61 end
rewrite_path(was, is = nil, opts=OPTS, &block)

Record a path rewrite from path was to path is. Options:

:path_info

Modify PATH_INFO, not just remaining path.

[show source]
   # File lib/roda/plugins/path_rewriter.rb
65 def rewrite_path(was, is = nil, opts=OPTS, &block)
66   if is.is_a? Hash
67     raise RodaError, "cannot provide two hashes to rewrite_path" unless opts.empty?
68     opts = is
69     is = nil
70   end
71 
72   if block
73     raise RodaError, "cannot provide both block and string replacement to rewrite_path" if is
74     is = block
75   end
76 
77   was = /\A#{Regexp.escape(was)}/ unless was.is_a?(Regexp)
78   array = @opts[opts[:path_info] ? :path_info_rewrites : :remaining_path_rewrites]
79   array << [was, is.dup.freeze].freeze
80 end