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.



60
61
62
63
64
# File 'lib/roda/plugins/path_rewriter.rb', line 60

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.



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

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