Class: Otto::Core::StaticMounts::StaticMount

Inherits:
Struct
  • Object
show all
Defined in:
lib/otto/core/static_mounts.rb

Overview

One registered mount. prefix is the normalized URL prefix ('' for a root mount), root the canonical directory, files the Rack::Files instance rooted there. Instances are frozen at construction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#files ⇒ Object

Returns the value of attribute files

Returns:

  • (Object) —

    the current value of files



42
43
44
# File 'lib/otto/core/static_mounts.rb', line 42

def files
  @files
end

#prefix ⇒ Object

Returns the value of attribute prefix

Returns:

  • (Object) —

    the current value of prefix



42
43
44
# File 'lib/otto/core/static_mounts.rb', line 42

def prefix
  @prefix
end

#root ⇒ Object

Returns the value of attribute root

Returns:

  • (Object) —

    the current value of root



42
43
44
# File 'lib/otto/core/static_mounts.rb', line 42

def root
  @root
end

Instance Method Details

#display_prefix ⇒ Object

Prefix as an operator would write it ('/' for a root mount).



58
59
60
# File 'lib/otto/core/static_mounts.rb', line 58

def display_prefix
  prefix.empty? ? '/' : prefix
end

#relative_path_for(path) ⇒ String?

Request-relative path under this mount, or nil when path is not beneath the prefix. The prefix itself (the directory) never matches: a mount serves files, not directory listings.

Parameters:

  • path (String) —

    normalized dispatch path (leading '/')

Returns:

  • (String, nil)


49
50
51
52
53
54
55
# File 'lib/otto/core/static_mounts.rb', line 49

def relative_path_for(path)
  if prefix.empty?
    path
  elsif path.start_with?("#{prefix}/")
    path[(prefix.length + 1)..]
  end
end