Module: Roda::RodaPlugins::PathRewriter::ClassMethods

Defined in:
lib/roda/plugins/path_rewriter.rb

Instance Method Summary collapse

Instance Method Details

#freezeObject

Freeze the path rewrite metadata.



57
58
59
60
61
# File 'lib/roda/plugins/path_rewriter.rb', line 57

def freeze
  opts[:remaining_path_rewrites].freeze
  opts[:path_info_rewrites].freeze
  super
end

#rewrite_path(was, is = nil, opts = OPTS, &block) ⇒ Object

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

:path_info

Modify PATH_INFO, not just remaining path.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/roda/plugins/path_rewriter.rb', line 65

def rewrite_path(was, is = nil, opts=OPTS, &block)
  if is.is_a? Hash
    raise RodaError, "cannot provide two hashes to rewrite_path" unless opts.empty?
    opts = is
    is = nil
  end

  if block
    raise RodaError, "cannot provide both block and string replacement to rewrite_path" if is
    is = block
  end

  was = /\A#{Regexp.escape(was)}/ unless was.is_a?(Regexp)
  array = @opts[opts[:path_info] ? :path_info_rewrites : :remaining_path_rewrites]
  array << [was, is.dup.freeze].freeze
end