Skip to content

Commit a29e212

Browse files
committed
add yard docs
1 parent a09d1b5 commit a29e212

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/hooks/app/helpers.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ module Hooks
66
module App
77
module Helpers
88
# Generate a unique identifier (UUID)
9+
#
10+
# @return [String] a new UUID string
911
def uuid
1012
SecureRandom.uuid
1113
end
1214

1315
# Enforce request size and timeout limits
16+
#
17+
# @param config [Hash] The configuration hash, must include :request_limit
18+
# @raise [StandardError] Halts with error if request body is too large
19+
# @return [void]
20+
# @note Timeout enforcement should be handled at the server level (e.g., Puma)
1421
def enforce_request_limits(config)
1522
# Check content length (handle different header formats and sources)
1623
content_length = headers["Content-Length"] || headers["CONTENT_LENGTH"] ||
@@ -30,6 +37,11 @@ def enforce_request_limits(config)
3037
end
3138

3239
# Parse request payload
40+
#
41+
# @param raw_body [String] The raw request body
42+
# @param headers [Hash] The request headers
43+
# @param symbolize [Boolean] Whether to symbolize keys in parsed JSON (default: true)
44+
# @return [Hash, String] Parsed JSON as Hash (optionally symbolized), or raw body if not JSON
3345
def parse_payload(raw_body, headers, symbolize: true)
3446
content_type = headers["Content-Type"] || headers["CONTENT_TYPE"] || headers["content-type"] || headers["HTTP_CONTENT_TYPE"]
3547

@@ -49,6 +61,12 @@ def parse_payload(raw_body, headers, symbolize: true)
4961
end
5062

5163
# Load handler class
64+
#
65+
# @param handler_class_name [String] The name of the handler class to load
66+
# @param handler_dir [String] The directory containing handler files
67+
# @return [Object] An instance of the loaded handler class
68+
# @raise [LoadError] If the handler file or class cannot be found
69+
# @raise [StandardError] Halts with error if handler cannot be loaded
5270
def load_handler(handler_class_name, handler_dir)
5371
# Convert class name to file name (e.g., Team1Handler -> team1_handler.rb)
5472
# E.g.2: GithubHandler -> github_handler.rb
@@ -67,6 +85,9 @@ def load_handler(handler_class_name, handler_dir)
6785
end
6886

6987
# Determine HTTP error code from exception
88+
#
89+
# @param exception [Exception] The exception to map to an HTTP status code
90+
# @return [Integer] The HTTP status code (400, 501, or 500)
7091
def determine_error_code(exception)
7192
case exception
7293
when ArgumentError then 400

0 commit comments

Comments
 (0)