Skip to content

Commit

Permalink
use tuples for http method instead of hash
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwalguptaofficial committed Apr 16, 2020
1 parent 3888b20 commit 88900b5
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test:general": "npm run test:general:dev && npm run test:general:prod",
"test:general:dev": "cd tests/general && CRYSTAL_ENV=TEST crystal spec e2e/* --error-trace",
"test:general:prod": "cd tests/general && CRYSTAL_ENV=production CLOSE_PROCESS=true crystal spec e2e/* --error-trace",
"test": "npm run test:general && npm run test:websocket",
"test": "npm run test:general && npm run test:server && npm run test:websocket",
"start": "cd tests/general && crystal src/general.cr --error-trace",
"start:dev": "cd tests/general && crystal src/general.cr --error-trace",
"start:prod": "cd tests/general && CRYSTAL_ENV=Production crystal src/general.cr --error-trace",
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/index.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "./route_handler"
require "./request_handler"
require "./injector_handler"


2 changes: 2 additions & 0 deletions src/handlers/request_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ require "../constants"
require "../helpers/index"
require "../generics/index"
require "../aliases"
require "../tuples/all"

module Shivneri
module Handlers
include CONSTANTS
include HELPER
include MODEL
include GENERIC
include TUPLE

class RequestHandler < PostHandler
getter query, context, route_match_info, session_provider, component_data
Expand Down
13 changes: 0 additions & 13 deletions src/hashes/http_method.cr

This file was deleted.

1 change: 0 additions & 1 deletion src/hashes/index.cr
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
require "./mime_type"
require "./http_method"
9 changes: 7 additions & 2 deletions src/model/worker_info.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ module Shivneri
# expectedQuery?: any;
# expectedBody?: any;

def initialize(workerName : String, httpMethods : Array(String), @workerProc)
def initialize(workerName : String, http_methods : Array(String), @workerProc)
@name = workerName
@pattern = "/#{workerName}"
@methodsAllowed = httpMethods.size == 0 ? HTTP_METHOD.values : httpMethods
@methodsAllowed = http_methods
if (http_methods.size == 0)
HTTP_METHOD.each_value do |value|
@methodsAllowed.push(value)
end
end
end

def to_json
Expand Down
1 change: 1 addition & 0 deletions src/tuples/all.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "./http_method"
Empty file removed src/tuples/folder_map.cr
Empty file.
13 changes: 13 additions & 0 deletions src/tuples/http_method.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Shivneri
module TUPLE
HTTP_METHOD = {
get: "GET",
post: "POST",
put: "PUT",
patch: "PATCH",
delete: "DELETE",
options: "OPTIONS",
head: "HEAD",
}
end
end

0 comments on commit 88900b5

Please sign in to comment.