Skip to content

Commit

Permalink
docs: fix @returns directive
Browse files Browse the repository at this point in the history
  • Loading branch information
aristotelesbr committed Jan 19, 2024
1 parent ffa79f6 commit d97e4c8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions lib/lennarb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class Lennarb
class LennarbError < StandardError; end

# @attribute [r] root
# @return [RouteNode]
# @returns [RouteNode]
#
attr_reader :root

# Initialize the application
#
# @yield { ... } The application
#
# @return [Lennarb]
# @returns [Lennarb]
#
def initialize
@root = RouteNode.new
Expand All @@ -42,7 +42,7 @@ def initialize
#
# @parameter [String] path
#
# @return [Array] parts. Ex. ['users', ':id']
# @returns [Array] parts. Ex. ['users', ':id']
#
SplitPath = ->(path) { path.split('/').reject(&:empty?) }
private_constant :SplitPath
Expand All @@ -51,16 +51,16 @@ def initialize
#
# @parameter [Hash] env
#
# @return [Array] response
# @returns [Array] response
#
def call(env)
res = Response.new
http_method = env.fetch('REQUEST_METHOD').to_sym
parts = SplitPath[env.fetch('PATH_INFO')]

block, params = @root.match_route(parts, http_method)
return [404, { 'content-type' => 'text/plain' }, ['Not Found']] unless block

res = Response.new
req = Request.new(env, params)
instance_exec(req, res, &block)

Expand All @@ -72,7 +72,7 @@ def call(env)
# @parameter [String] path
# @parameter [Proc] block
#
# @return [void]
# @returns [void]
#
def get(path, &block) = add_route(path, :GET, block)
def post(path, &block) = add_route(path, :POST, block)
Expand All @@ -88,7 +88,7 @@ def delete(path, &block) = add_route(path, :DELETE, block)
# @parameter [String] http_method
# @parameter [Proc] block
#
# @return [void]
# @returns [void]
#
def add_route(path, http_method, block)
parts = SplitPath[path]
Expand Down
6 changes: 3 additions & 3 deletions lib/lennarb/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Request < Rack::Request
# @parameter [Hash] env
# @parameter [Hash] route_params
#
# @return [Request]
# @returns [Request]
#
def initialize(env, route_params = {})
super(env)
Expand All @@ -19,7 +19,7 @@ def initialize(env, route_params = {})

# Get the request body
#
# @return [String]
# @returns [String]
def params
@params ||= super.merge(@route_params)
end
Expand All @@ -28,7 +28,7 @@ def params

# Get the query string
#
# @return [String]
# @returns [String]
#
def query_params
@query_params ||= Rack::Utils.parse_nested_query(query_string)
Expand Down
24 changes: 12 additions & 12 deletions lib/lennarb/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
class Lennarb
class Response
# @!attribute [rw] status
# @return [Integer]
# @returns [Integer]
#
attr_accessor :status

# @!attribute [r] body
# @return [Array]
# @returns [Array]
#
attr_reader :body

# @!attribute [r] headers
# @return [Hash]
# @returns [Hash]
#
attr_reader :headers

# @!attribute [r] length
# @return [Integer]
# @returns [Integer]
#
attr_reader :length

Expand All @@ -41,7 +41,7 @@ class Response

# Initialize the response object
#
# @return [Response]
# @returns [Response]
#
def initialize
@status = 404
Expand All @@ -54,7 +54,7 @@ def initialize
#
# @parameter [String] key
#
# @return [String] value
# @returns [String] value
#
def [](key)
@headers[key]
Expand All @@ -65,7 +65,7 @@ def [](key)
# @parameter [String] key
# @parameter [String] value
#
# @return [String] value
# @returns [String] value
#
def []=(key, value)
@headers[key] = value
Expand All @@ -75,7 +75,7 @@ def []=(key, value)
#
# @parameter [String] str
#
# @return [String] str
# @returns [String] str
#
def write(str)
str = str.to_s
Expand All @@ -88,7 +88,7 @@ def write(str)
#
# @parameter [String] str
#
# @return [String] str
# @returns [String] str
#
def text(str)
@headers[CONTENT_TYPE] = ContentType[:TEXT]
Expand All @@ -99,7 +99,7 @@ def text(str)
#
# @parameter [String] str
#
# @return [String] str
# @returns [String] str
#
def html(str)
@headers[CONTENT_TYPE] = ContentType[:HTML]
Expand All @@ -110,7 +110,7 @@ def html(str)
#
# @parameter [String] str
#
# @return [String] str
# @returns [String] str
#
def json(str)
@headers[CONTENT_TYPE] = ContentType[:JSON]
Expand All @@ -129,7 +129,7 @@ def redirect(path, status = 302)

# Finish the response
#
# @return [Array] response
# @returns [Array] response
#
def finish
[@status, @headers, @body]
Expand Down
2 changes: 1 addition & 1 deletion lib/lennarb/route_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RouteNode
# @return [RouteNode]
#
def initialize
@children = {}
@children = {}
@blocks = {}
@param_key = nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/lennarb/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright, 2023-2024, by Aristóteles Coutinho.

class Lennarb
VERSION = '0.2.0'
VERSION = '0.3.0'

public_constant :VERSION
end

0 comments on commit d97e4c8

Please sign in to comment.