Sha256: 0f4add44974c2ccc3da956010a2b92b8dc9617410679f3e55237a9cb058167e8

Contents?: true

Size: 1.17 KB

Versions: 88

Compression:

Stored size: 1.17 KB

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The strip_path_prefix plugin makes Roda strip a given prefix off internal absolute paths,
    # turning them to relative paths.  Roda by default stores internal paths as absolute paths.
    # The main reason to use this plugin is when the internal absolute path could change at
    # runtime, either due to a symlink change or chroot call, or you really want to use
    # relative paths instead of absolute paths.
    # 
    # Examples:
    #
    #   plugin :strip_path_prefix # Defaults to Dir.pwd
    #   plugin :strip_path_prefix, File.dirname(Dir.pwd)
    module StripPathPrefix
      # Set the regexp to use when stripping prefixes from internal paths.
      def self.configure(app, prefix=Dir.pwd)
        prefix += '/' unless prefix=~ /\/\z/
        app.opts[:strip_path_prefix] = /\A#{Regexp.escape(prefix)}/
      end

      module ClassMethods
        # Strip the path prefix from the gien path if it starts with the prefix.
        def expand_path(path, root=opts[:root])
          super.sub(opts[:strip_path_prefix], '')
        end
      end
    end

    register_plugin(:strip_path_prefix, StripPathPrefix)
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
roda-3.86.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.85.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.84.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.83.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.82.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.81.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.79.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.78.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.77.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.76.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.75.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.74.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.73.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.72.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.71.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.70.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.69.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.68.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.67.0 lib/roda/plugins/strip_path_prefix.rb
roda-3.66.0 lib/roda/plugins/strip_path_prefix.rb