|
|
@ -5,12 +5,16 @@ require_relative 'node' |
|
|
|
require_relative 'dsl/constructors_path' |
|
|
|
require_relative 'dsl/methods_path' |
|
|
|
require_relative 'dsl/methods_common' |
|
|
|
require_relative 'dsl/methods_probe' |
|
|
|
require_relative 'dsl/constructors_probe' |
|
|
|
require_relative 'util/lookup' |
|
|
|
|
|
|
|
module Landline |
|
|
|
# Execution context for filters and preprocessors. |
|
|
|
class ProcessorContext |
|
|
|
include Landline::DSL::CommonMethods |
|
|
|
include Landline::DSL::ProbeMethods |
|
|
|
include Landline::DSL::ProbeConstructors |
|
|
|
|
|
|
|
def initialize(path) |
|
|
|
@origin = path |
|
|
@ -54,21 +58,11 @@ module Landline |
|
|
|
# @return [Boolean] true if further navigation will be done |
|
|
|
# @raise [UncaughtThrowError] by default throws :response if no matches found. |
|
|
|
def process(request) |
|
|
|
return false unless run_filters(request) |
|
|
|
|
|
|
|
run_preprocessors(request) |
|
|
|
enqueue_postprocessors(request) |
|
|
|
@children.each do |x| |
|
|
|
if (value = x.go(request)) |
|
|
|
return value |
|
|
|
end |
|
|
|
if @pipeline |
|
|
|
@pipeline.call(request) { |inner_req| process_wrapped(inner_req) } |
|
|
|
else |
|
|
|
process_wrapped(request) |
|
|
|
end |
|
|
|
value = index(request) |
|
|
|
return value if value |
|
|
|
|
|
|
|
_die(404) |
|
|
|
rescue StandardError => e |
|
|
|
_die(500, backtrace: [e.to_s] + e.backtrace) |
|
|
|
end |
|
|
|
|
|
|
|
# Add a preprocessor to the path. |
|
|
@ -95,7 +89,9 @@ module Landline |
|
|
|
@filters.append(block) |
|
|
|
end |
|
|
|
|
|
|
|
attr_reader :children, :properties |
|
|
|
attr_reader :children, :properties, :request |
|
|
|
|
|
|
|
attr_accessor :bounce, :pipeline |
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
@ -123,6 +119,31 @@ module Landline |
|
|
|
request.postprocessors.append(*@postprocessors) |
|
|
|
end |
|
|
|
|
|
|
|
# Method callback on successful request navigation. |
|
|
|
# Finds the next appropriate path to go to. |
|
|
|
# (inner pipeline-wrapped handler) |
|
|
|
# @return [Boolean] true if further navigation will be done |
|
|
|
# @raise [UncaughtThrowError] by default throws :response if no matches found. |
|
|
|
def process_wrapped(request) |
|
|
|
@request = request |
|
|
|
return false unless run_filters(request) |
|
|
|
|
|
|
|
run_preprocessors(request) |
|
|
|
enqueue_postprocessors(request) |
|
|
|
@children.each do |x| |
|
|
|
value = x.go(request) |
|
|
|
return value if value |
|
|
|
end |
|
|
|
value = index(request) |
|
|
|
return value if value |
|
|
|
|
|
|
|
@bounce ? false : _die(404) |
|
|
|
rescue StandardError => e |
|
|
|
_die(500, backtrace: [e.to_s] + e.backtrace) |
|
|
|
ensure |
|
|
|
@request = nil |
|
|
|
end |
|
|
|
|
|
|
|
# Try to perform indexing on the path if possible |
|
|
|
# @param request [Landline::Request] |
|
|
|
# @return [Boolean] true if indexing succeeded |
|
|
@ -146,11 +167,12 @@ module Landline |
|
|
|
# @raise [UncaughtThrowError] throws :finish to stop processing |
|
|
|
def _die(errorcode, backtrace: nil) |
|
|
|
throw :finish, [errorcode].append( |
|
|
|
*(@properties["handle.#{errorcode}"] or |
|
|
|
@properties["handle.default"]).call( |
|
|
|
errorcode, |
|
|
|
backtrace: backtrace |
|
|
|
) |
|
|
|
*@proccontext.instance_exec( |
|
|
|
errorcode, |
|
|
|
backtrace: backtrace, |
|
|
|
&(@properties["handle.#{errorcode}"] or |
|
|
|
@properties["handle.default"]) |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|