From c37dcf47e05ebbbe3c61216a3f13473d68f512f9 Mon Sep 17 00:00:00 2001 From: Yessiest Date: Sat, 23 Sep 2023 00:48:21 +0400 Subject: [PATCH] Bumped gem version, added flag to ignore filepath modification in a node --- landline.gemspec | 2 +- lib/landline/dsl/constructors_path.rb | 73 +++++++++++++++++++-------- lib/landline/node.rb | 6 ++- lib/landline/path.rb | 4 +- lib/landline/probe.rb | 4 +- lib/landline/probe/handler.rb | 4 +- lib/landline/probe/serve_handler.rb | 2 +- lib/landline/server.rb | 4 +- 8 files changed, 66 insertions(+), 33 deletions(-) diff --git a/landline.gemspec b/landline.gemspec index 790035d..1d7a2f9 100644 --- a/landline.gemspec +++ b/landline.gemspec @@ -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. diff --git a/lib/landline/dsl/constructors_path.rb b/lib/landline/dsl/constructors_path.rb index 19c9805..8c8d8da 100644 --- a/lib/landline/dsl/constructors_path.rb +++ b/lib/landline/dsl/constructors_path.rb @@ -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 diff --git a/lib/landline/node.rb b/lib/landline/node.rb index 12b379d..55fe2bf 100644 --- a/lib/landline/node.rb +++ b/lib/landline/node.rb @@ -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 diff --git a/lib/landline/path.rb b/lib/landline/path.rb index c3fd8c6..77358bd 100644 --- a/lib/landline/path.rb +++ b/lib/landline/path.rb @@ -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 diff --git a/lib/landline/probe.rb b/lib/landline/probe.rb index 80d483e..777f8b6 100644 --- a/lib/landline/probe.rb +++ b/lib/landline/probe.rb @@ -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 diff --git a/lib/landline/probe/handler.rb b/lib/landline/probe/handler.rb index 139e9b9..660c0cb 100644 --- a/lib/landline/probe/handler.rb +++ b/lib/landline/probe/handler.rb @@ -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 diff --git a/lib/landline/probe/serve_handler.rb b/lib/landline/probe/serve_handler.rb index bc5450f..4c04107 100644 --- a/lib/landline/probe/serve_handler.rb +++ b/lib/landline/probe/serve_handler.rb @@ -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 diff --git a/lib/landline/server.rb b/lib/landline/server.rb index 483645a..3309227 100644 --- a/lib/landline/server.rb +++ b/lib/landline/server.rb @@ -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 {