Class: Hyde::Handlers::Serve

Inherits:
Probe show all
Defined in:
lib/hyde/probe/serve_handler.rb

Overview

Probe that sends files from a location

Instance Attribute Summary collapse

Attributes inherited from Probe

#properties

Attributes inherited from Node

#remap, #root

Instance Method Summary collapse

Methods inherited from Node

#go, #reject

Constructor Details

#initialize(path, parent:) ⇒ Serve

Returns a new instance of Serve.

Parameters:



12
13
14
# File 'lib/hyde/probe/serve_handler.rb', line 12

def initialize(path, parent:)
  super(path, parent: parent)
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



16
17
18
# File 'lib/hyde/probe/serve_handler.rb', line 16

def response
  @response
end

Instance Method Details

#process(request) ⇒ Boolean

Method callback on successful request navigation. Tries to serve files matched by handler

Parameters:

Returns:

  • (Boolean)

    true if file was found



22
23
24
25
26
27
28
29
# File 'lib/hyde/probe/serve_handler.rb', line 22

def process(request)
  path = File.expand_path(request.filepath)
  return unless path.start_with? @properties["path"]

  File.open(path.delete_suffix("/"))
rescue StandardError
  false
end