Class: Simple::Httpd::Mount::PathMount

Inherits:
Object
  • Object
show all
Defined in:
lib/simple/httpd/mount.rb

Constant Summary collapse

Rack =
::Simple::Httpd::Rack

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mount_point, path) ⇒ PathMount

Returns a new instance of PathMount.



50
51
52
# File 'lib/simple/httpd/mount.rb', line 50

def initialize(mount_point, path)
  @mount_point, @path = mount_point, path
end

Instance Attribute Details

#mount_pointObject (readonly)

Returns the value of attribute mount_point.



38
39
40
# File 'lib/simple/httpd/mount.rb', line 38

def mount_point
  @mount_point
end

#pathObject (readonly)

Returns the value of attribute path.



38
39
40
# File 'lib/simple/httpd/mount.rb', line 38

def path
  @path
end

Class Method Details

.build(mount_point, path:) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
48
# File 'lib/simple/httpd/mount.rb', line 40

def self.build(mount_point, path:)
  mount_point = mount_point.gsub(/\/.$/, "/") # shorting trailing "/." to "/"
  path        = path.gsub(/\/$/, "")          # remove trailing "/"

  raise ArgumentError, "You probably don't want to mount your root directory, check mount" if path == ""
  return unless Dir.exist?(path)

  new(mount_point, path)
end

Instance Method Details

#build_rack_appsObject



60
61
62
63
64
65
66
67
# File 'lib/simple/httpd/mount.rb', line 60

def build_rack_apps
  return @build_rack_apps if @build_rack_apps

  dynamic_mount = Rack::DynamicMount.build(mount_point, path)
  static_mount = Rack::StaticMount.build(mount_point, path)

  @build_rack_apps = [dynamic_mount, static_mount].compact
end

#route_descriptionsObject



54
55
56
57
58
# File 'lib/simple/httpd/mount.rb', line 54

def route_descriptions
  build_rack_apps.inject([]) do |ary, app|
    ary.concat app.route_descriptions
  end
end