Class: Landline::Handlers::Serve
- Defined in:
- lib/landline/probe/serve_handler.rb
Overview
Probe that sends files from a location
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Attributes inherited from Probe
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(path, parent:) ⇒ Serve
constructor
A new instance of Serve.
-
#process(request) ⇒ Boolean, Array
Method callback on successful request navigation.
Methods inherited from Node
Constructor Details
#initialize(path, parent:) ⇒ Serve
Returns a new instance of Serve.
13 14 15 |
# File 'lib/landline/probe/serve_handler.rb', line 13 def initialize(path, parent:) super(path, parent: parent, filepath: true) end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
17 18 19 |
# File 'lib/landline/probe/serve_handler.rb', line 17 def response @response end |
Instance Method Details
#process(request) ⇒ Boolean, Array
Method callback on successful request navigation. Tries to serve files matched by handler
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/landline/probe/serve_handler.rb', line 23 def process(request) path = File.(request.filepath) return unless path.start_with? @properties["path"] filepath = path.delete_suffix("/") [200, { "content-type" => Landline::MIME.get_mime_type(filepath) }, File.open(filepath)] rescue StandardError false end |