Module: Hyde::DSL::ProbeMethods
- Included in:
- ProbeBinding
- Defined in:
- lib/hyde/dsl/probe_methods.rb
Overview
Common methods for Probe objects
Instance Method Summary collapse
-
#bounce ⇒ Object
Bounce request to the next handler.
-
#die(errorcode, backtrace: nil) ⇒ Object
Stop execution and generate a boilerplate response with the given code.
-
#header(key, value) ⇒ Object
Set response header (generate response if one doesn’t exist yet).
-
#remove_header(key, value = nil) ⇒ Object
Delete a header value from the headers hash If no value is provided, deletes all key entries.
-
#request ⇒ Hyde::Request
Get the current request.
-
#status(status) ⇒ Object
(also: #code)
Set response status (generate response if one doesn’t exist yet).
Instance Method Details
#bounce ⇒ Object
Bounce request to the next handler
31 32 33 |
# File 'lib/hyde/dsl/probe_methods.rb', line 31 def bounce throw :break end |
#die(errorcode, backtrace: nil) ⇒ Object
Stop execution and generate a boilerplate response with the given code
19 20 21 22 23 24 25 26 27 |
# File 'lib/hyde/dsl/probe_methods.rb', line 19 def die(errorcode, backtrace: nil) throw :finish, [errorcode].append( *(@origin.properties["handle.#{errorcode}"] or @origin.properties["handle.default"]).call( errorcode, backtrace: backtrace ) ) end |
#header(key, value) ⇒ Object
Set response header (generate response if one doesn’t exist yet)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/hyde/dsl/probe_methods.rb', line 47 def header(key, value) return status(value) if key.downcase == "status" if key.match(/(?:[(),\/:;<=>?@\[\]{}"]|[^ -~])/) raise StandardError, "header key has invalid characters" end if value.match(/[^ -~]/) raise StandardError, "value key has invalid characters" end @origin.response = (@origin.response or Hyde::Response.new) key = key.downcase @origin.response.add_header(key, value) end |
#remove_header(key, value = nil) ⇒ Object
Delete a header value from the headers hash If no value is provided, deletes all key entries
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hyde/dsl/probe_methods.rb', line 67 def remove_header(key, value = nil) return unless @origin.response return if key.downcase == "status" if key.match(/(?:[(),\/:;<=>?@\[\]{}"]|[^ -~])/) raise StandardError, "header key has invalid characters" end if value&.match(/[^ -~]/) raise StandardError, "value key has invalid characters" end @origin.response.delete_header(key, value) end |
#request ⇒ Hyde::Request
Get the current request
11 12 13 |
# File 'lib/hyde/dsl/probe_methods.rb', line 11 def request @origin.request end |