File tree 4 files changed +30
-4
lines changed
4 files changed +30
-4
lines changed Original file line number Diff line number Diff line change
1
+ dependencies :
2
+ # Assuming we have a conflict with the version of the Redis shard
3
+ # This will override any specified version and use the `master` branch instead
4
+ lucky_router :
5
+ github : luckyframework/lucky_router
6
+ branch : main
Original file line number Diff line number Diff line change @@ -23,4 +23,16 @@ describe Lucky::Router do
23
23
Lucky .router.find_action(:get , " /complex_path/1/2" ).should_not be_nil
24
24
Lucky .router.find_action(:get , " /complex_path/1" ).should_not be_nil
25
25
end
26
+
27
+ describe " #list_routes" do
28
+ it " returns list of routes" do
29
+ Lucky .router.add :get , " /users" , Lucky ::Action
30
+ Lucky .router.add :put , " /clients/:client_id" , Lucky ::Action
31
+
32
+ routes = Lucky .router.list_routes
33
+
34
+ routes.should contain({" /users" , " get" , Lucky ::Action })
35
+ routes.should contain({" /clients/:client_id" , " put" , Lucky ::Action })
36
+ end
37
+ end
26
38
end
Original file line number Diff line number Diff line change 1
1
# :nodoc:
2
2
class Lucky::Router
3
- getter routes = [] of Tuple (Symbol , String , Lucky ::Action .class)
4
3
@matcher = LuckyRouter ::Matcher (Lucky ::Action .class).new
5
4
5
+ # Array of path, method, and payload
6
+ def list_routes : Array (Tuple (String , String , Lucky ::Action .class))
7
+ @matcher .list_routes
8
+ end
9
+
6
10
def add (method : Symbol , path : String , action : Lucky ::Action .class) : Nil
7
- @routes << {method, path, action}
8
11
@matcher .add(method.to_s, path, action)
9
12
end
10
13
Original file line number Diff line number Diff line change @@ -22,9 +22,14 @@ class Routes < LuckyTask::Task
22
22
def call
23
23
routes = [] of Array (String )
24
24
25
- Lucky .router.routes.each do |method , path , action |
25
+ Lucky .router.list_routes.each do |path , method , action |
26
+ # skip HEAD routes
27
+ # LuckyRouter creates these routes from any GET routes submitted
28
+ # This could be an issue if users define their own HEAD routes
29
+ next if method.upcase == " HEAD"
30
+
26
31
row = [] of String
27
- row << method.to_s. upcase
32
+ row << method.upcase
28
33
row << path.colorize.green.to_s
29
34
row << action.name
30
35
routes << row
You can’t perform that action at this time.
0 commit comments