module Rack::App::SingletonMethods::MOUNT
Constants
- MOUNT
Public Instance Methods
mount(app, options={})
click to toggle source
# File lib/rack/app/singleton_methods/mounting.rb, line 4 def mount(app, options={}) case when app.is_a?(Class) && app < ::Rack::App mount_rack_app(app, options) when app.respond_to?(:call) mount_rack_interface_compatible_application(app, options) else raise(NotImplementedError) end end
mount_directory(directory_path, options={})
click to toggle source
# File lib/rack/app/singleton_methods/mounting.rb, line 34 def mount_directory(directory_path, options={}) directory_full_path = ::Rack::App::Utils.expand_path(directory_path) namespace options[:to] do Dir.glob(File.join(directory_full_path, '**', '*')).each do |file_path| request_path = file_path.sub(/^#{Regexp.escape(directory_full_path)}/, '') get(request_path) { serve_file(file_path) } options(request_path) { '' } end end nil end
mount_rack_app(app, options={})
click to toggle source
# File lib/rack/app/singleton_methods/mounting.rb, line 15 def mount_rack_app(app, options={}) options.freeze unless app.is_a?(Class) and app <= Rack::App raise(ArgumentError, 'Invalid class given for mount, must be a Rack::App') end cli.merge!(app.cli) merge_prop = { :namespaces => [@namespaces, options[:to]].flatten, :new_ancestor => self } router.merge_router!(app.router, merge_prop) nil end
mount_rack_interface_compatible_application(rack_based_app, options={})
click to toggle source
# File lib/rack/app/singleton_methods/mounting.rb, line 56 def mount_rack_interface_compatible_application(rack_based_app, options={}) request_path = Rack::App::Utils.join(options[:to],Rack::App::Constants::PATH::APPLICATION) add_route(::Rack::App::Constants::HTTP::METHOD::ANY, request_path, rack_based_app) end
serve_files_from(dir_path, options={})
click to toggle source
# File lib/rack/app/singleton_methods/mounting.rb, line 49 def serve_files_from(dir_path, options={}) file_server = Rack::App::FileServer.new(Rack::App::Utils.expand_path(dir_path)) request_path = Rack::App::Utils.join(options[:to], Rack::App::Constants::PATH::MOUNT_POINT) add_route(::Rack::App::Constants::HTTP::METHOD::ANY, request_path, file_server) nil end