Skip to content

Commit 88900b5

Browse files
use tuples for http method instead of hash
1 parent 3888b20 commit 88900b5

File tree

9 files changed

+26
-17
lines changed

9 files changed

+26
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test:general": "npm run test:general:dev && npm run test:general:prod",
1212
"test:general:dev": "cd tests/general && CRYSTAL_ENV=TEST crystal spec e2e/* --error-trace",
1313
"test:general:prod": "cd tests/general && CRYSTAL_ENV=production CLOSE_PROCESS=true crystal spec e2e/* --error-trace",
14-
"test": "npm run test:general && npm run test:websocket",
14+
"test": "npm run test:general && npm run test:server && npm run test:websocket",
1515
"start": "cd tests/general && crystal src/general.cr --error-trace",
1616
"start:dev": "cd tests/general && crystal src/general.cr --error-trace",
1717
"start:prod": "cd tests/general && CRYSTAL_ENV=Production crystal src/general.cr --error-trace",

src/handlers/index.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
require "./route_handler"
22
require "./request_handler"
33
require "./injector_handler"
4+
5+

src/handlers/request_handler.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ require "../constants"
66
require "../helpers/index"
77
require "../generics/index"
88
require "../aliases"
9+
require "../tuples/all"
910

1011
module Shivneri
1112
module Handlers
1213
include CONSTANTS
1314
include HELPER
1415
include MODEL
1516
include GENERIC
17+
include TUPLE
1618

1719
class RequestHandler < PostHandler
1820
getter query, context, route_match_info, session_provider, component_data

src/hashes/http_method.cr

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/hashes/index.cr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
require "./mime_type"
2-
require "./http_method"

src/model/worker_info.cr

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ module Shivneri
1313
# expectedQuery?: any;
1414
# expectedBody?: any;
1515

16-
def initialize(workerName : String, httpMethods : Array(String), @workerProc)
16+
def initialize(workerName : String, http_methods : Array(String), @workerProc)
1717
@name = workerName
1818
@pattern = "/#{workerName}"
19-
@methodsAllowed = httpMethods.size == 0 ? HTTP_METHOD.values : httpMethods
19+
@methodsAllowed = http_methods
20+
if (http_methods.size == 0)
21+
HTTP_METHOD.each_value do |value|
22+
@methodsAllowed.push(value)
23+
end
24+
end
2025
end
2126

2227
def to_json

src/tuples/all.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require "./http_method"

src/tuples/folder_map.cr

Whitespace-only changes.

src/tuples/http_method.cr

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Shivneri
2+
module TUPLE
3+
HTTP_METHOD = {
4+
get: "GET",
5+
post: "POST",
6+
put: "PUT",
7+
patch: "PATCH",
8+
delete: "DELETE",
9+
options: "OPTIONS",
10+
head: "HEAD",
11+
}
12+
end
13+
end

0 commit comments

Comments
 (0)