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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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