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.



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

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
# File 'lib/simple/httpd/mount.rb', line 40

def self.build(mount_point, path:)
  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



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

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

  [dynamic_mount, static_mount].compact
end

#route_descriptionsObject



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

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