Bumped gem version, added flag to ignore filepath modification in a node

This commit is contained in:
Yessiest 2023-09-23 00:48:21 +04:00
parent 6e6ff6151f
commit c37dcf47e0
8 changed files with 66 additions and 33 deletions

View File

@ -2,7 +2,7 @@
Gem::Specification.new do |spec|
spec.name = "landline"
spec.version = "0.9.1"
spec.version = "0.9.2"
spec.summary = "Elegant HTTP DSL"
spec.description = <<~DESC
Landline is a no-hard-dependencies HTTP routing DSL that was made entirely for fun.

View File

@ -15,58 +15,87 @@ module Landline
end
# Create a new {Landline::Path} object
def path(path, &setup)
register(Landline::Path.new(path, parent: @origin, &setup))
def path(path, **args, &setup)
register(Landline::Path.new(path, parent: @origin, **args, &setup))
end
# Create a new {Landline::Handlers::Probe} object
def probe(path, &_setup)
register(Landline::Handlers::Probe.new(path, parent: @origin))
def probe(path, **args, &_setup)
register(Landline::Handlers::Probe.new(path,
parent: @origin,
**args))
end
# Create a new {Landline::Handlers::GETHandler} object
def get(path, &setup)
register(Landline::Handlers::GET.new(path, parent: @origin, &setup))
def get(path, **args, &setup)
register(Landline::Handlers::GET.new(path,
parent: @origin,
**args,
&setup))
end
# create a new {Landline::Handlers::POSTHandler} object
def post(path, &setup)
register(Landline::Handlers::POST.new(path, parent: @origin, &setup))
def post(path, **args, &setup)
register(Landline::Handlers::POST.new(path,
parent: @origin,
**args,
&setup))
end
# Create a new {Landline::Handlers::PUTHandler} object
def put(path, &setup)
register(Landline::Handlers::PUT.new(path, parent: @origin, &setup))
def put(path, **args, &setup)
register(Landline::Handlers::PUT.new(path,
parent: @origin,
**args,
&setup))
end
# Create a new {Landline::Handlers::HEADHandler} object
def head(path, &setup)
register(Landline::Handlers::HEAD.new(path, parent: @origin, &setup))
def head(path, **args, &setup)
register(Landline::Handlers::HEAD.new(path,
parent: @origin,
**args,
&setup))
end
# Create a new {Landline::Handlers::DELETEHandler} object
def delete(path, &setup)
register(Landline::Handlers::DELETE.new(path, parent: @origin, &setup))
def delete(path, **args, &setup)
register(Landline::Handlers::DELETE.new(path,
parent: @origin,
**args,
&setup))
end
# Create a new {Landline::Handlers::CONNECTHandler} object
def connect(path, &setup)
register(Landline::Handlers::CONNECT.new(path, parent: @origin, &setup))
def connect(path, **args, &setup)
register(Landline::Handlers::CONNECT.new(path,
parent: @origin,
**args,
&setup))
end
# Create a new {Landline::Handlers::TRACEHandler} object
def trace(path, &setup)
register(Landline::Handlers::TRACE.new(path, parent: @origin, &setup))
def trace(path, **args, &setup)
register(Landline::Handlers::TRACE.new(path,
parent: @origin,
**args,
&setup))
end
# Create a new {Landline::Handlers::PATCHHandler} object
def patch(path, &setup)
register(Landline::Handlers::PATCH.new(path, parent: @origin, &setup))
def patch(path, **args, &setup)
register(Landline::Handlers::PATCH.new(path,
parent: @origin,
**args,
&setup))
end
# Create a new {Landline::Handlers::OPTIONSHandler} object
def options(path, &setup)
register(Landline::Handlers::OPTIONS.new(path, parent: @origin, &setup))
def options(path, **args, &setup)
register(Landline::Handlers::OPTIONS.new(path,
parent: @origin,
**args,
&setup))
end
# Create a new {Landline::Handlers::GETHandler} that serves static files

View File

@ -9,11 +9,13 @@ module Landline
# @abstract
class Node
# @param path [Object]
def initialize(path, parent:)
# @param filepath [Boolean] should Node modify request.filepath.
def initialize(path, parent:, filepath: true)
@pattern = Pattern.new(path).freeze
@properties = Landline::Util::Lookup.new(parent&.properties)
@root = nil
@remap = false
@modify_filepath = filepath
end
# Set Node file root (like root in Nginx)
@ -72,6 +74,8 @@ module Landline
# Process filepath for request
def do_filepath(request, path)
return unless @modify_filepath
if @root
request.filepath = "#{@root}/#{@remap ? '' : path}/"
else

View File

@ -35,8 +35,8 @@ module Landline
# @param path [Object] Object to generate {Landline::Pattern} from
# @param parent [Landline::Node] Parent object to inherit properties to
# @param setup [#call] Setup block
def initialize(path, parent:, &setup)
super(path, parent: parent)
def initialize(path, parent:, **params, &setup)
super(path, parent: parent, **params)
# Child nodes array
@children = []
# Arrays of preprocessors, postprocessors and filters

View File

@ -38,8 +38,8 @@ module Landline
class Probe < Landline::Node
# @param path [Object]
# @param parent [Landline::Node]
def initialize(path, parent:)
super(path, parent: parent)
def initialize(path, parent:, **params)
super(path, parent: parent, **params)
end
attr_reader :properties

View File

@ -9,8 +9,8 @@ module Landline
# @param path [Object]
# @param parent [Landline::Node]
# @param exec [#call]
def initialize(path, parent:, &exec)
super(path, parent: parent)
def initialize(path, **args, &exec)
super(path, **args)
@callback = exec
@context = Landline::ProbeContext.new(self)
@response = nil

View File

@ -11,7 +11,7 @@ module Landline
# @param parent [Landline::Node]
# @param exec [#call]
def initialize(path, parent:)
super(path, parent: parent)
super(path, parent: parent, filepath: true)
end
attr_accessor :response

View File

@ -14,8 +14,8 @@ module Landline
# @param parent [Landline::Node, nil] Parent object to inherit properties to
# @param setup [#call] Setup block
def initialize(parent: nil, &setup)
super("", parent: parent, &setup)
def initialize(parent: nil, **args, &setup)
super("", parent: nil, **args, &setup)
return if parent
{