@@ -76,13 +76,13 @@ def setup_page_route(req, slug, page_data)
7676
7777 def setup_resource_routes ( req , slug , options :)
7878 req . on slug do
79- setup_collection_routes ( req , slug , options : options )
80- setup_member_routes ( req , slug , options : options )
79+ repository = options [ :repository ] . new ( options [ :model ] )
80+ setup_collection_routes ( req , slug , options : options , repository : repository )
81+ setup_member_routes ( req , slug , options : options , repository : repository )
8182 end
8283 end
8384
84- def setup_collection_routes ( req , slug , options :)
85- repository = options [ :repository ] . new ( options [ :model ] )
85+ def setup_collection_routes ( req , slug , options :, repository :)
8686 action_options = options [ :index ] || { }
8787
8888 # Custom actions
@@ -112,8 +112,7 @@ def setup_collection_routes(req, slug, options:)
112112 end
113113 end
114114
115- def setup_member_routes ( req , slug , options :)
116- repository = options [ :repository ] . new ( options [ :model ] )
115+ def setup_member_routes ( req , slug , options :, repository :)
117116 action_options = ( options [ :show ] || { } ) . merge ( record_not_found_page : TinyAdmin . settings . record_not_found )
118117
119118 req . on String do |reference |
@@ -149,10 +148,10 @@ def setup_member_routes(req, slug, options:)
149148
150149 def setup_custom_actions ( req , custom_actions = nil , options :, repository :, slug :, reference : nil )
151150 ( custom_actions || [ ] ) . each_with_object ( { } ) do |custom_action , result |
152- action_slug , action = custom_action . first
153- action_class = to_class ( action )
151+ action_slug , action_config = custom_action . first
152+ action_class , http_method = parse_action_config ( action_config )
154153
155- req . get action_slug . to_s do
154+ req . public_send ( http_method , action_slug . to_s ) do
156155 authorize! ( :custom_action , action_slug . to_s ) do
157156 context = Context . new (
158157 actions : { } ,
@@ -171,6 +170,16 @@ def setup_custom_actions(req, custom_actions = nil, options:, repository:, slug:
171170 end
172171 end
173172
173+ def parse_action_config ( config )
174+ if config . is_a? ( Hash )
175+ action_class = to_class ( config [ :action ] || config [ "action" ] )
176+ http_method = ( config [ :method ] || config [ "method" ] || "get" ) . to_sym
177+ [ action_class , http_method ]
178+ else
179+ [ to_class ( config ) , :get ]
180+ end
181+ end
182+
174183 def authorization
175184 TinyAdmin . settings . authorization_class
176185 end
0 commit comments