Class: Simple::Httpd::Rack::StaticMount
- Inherits:
-
Object
- Object
- Simple::Httpd::Rack::StaticMount
- Includes:
- Simple::Httpd::RouteDescriptions
- Defined in:
- lib/simple/httpd/rack/static_mount.rb
Overview
A simple file server middleware
Constant Summary collapse
- H =
::Simple::Httpd::Helpers
- Rack =
::Simple::Httpd::Rack
- EXTENSIONS =
%w(.txt .md .js .css .png .jpeg .jpg .html)
- GLOB_PATTERN =
"**/*.{#{EXTENSIONS.map { |s| s[1..-1] }.join(",")}}"
Instance Attribute Summary collapse
-
#mount_point ⇒ Object
readonly
Returns the value of attribute mount_point.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Simple::Httpd::RouteDescriptions
#describe_route!, #route_descriptions
Instance Attribute Details
#mount_point ⇒ Object (readonly)
Returns the value of attribute mount_point.
27 28 29 |
# File 'lib/simple/httpd/rack/static_mount.rb', line 27 def mount_point @mount_point end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
27 28 29 |
# File 'lib/simple/httpd/rack/static_mount.rb', line 27 def path @path end |
Class Method Details
.build(mount_point, path) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/simple/httpd/rack/static_mount.rb', line 9 def self.build(mount_point, path) static_files = Dir.chdir(path) { Dir.glob(GLOB_PATTERN) } return nil if static_files.empty? ::Simple::Httpd.logger.info do "#{mount_point}: serving #{static_files.count} static file(s)" end if ::Simple::Httpd.logger.debug? static_files.sort.each do |file| ::Simple::Httpd.logger.debug "#{mount_point}/#{file}" end end new(mount_point, path, static_files) end |