Help with reorganizing my files structures (hash_routes)

32 visualizações
Pular para a primeira mensagem não lida

Diego Viola

não lida,
29 de out. de 2021, 00:27:2029/10/2021
para Roda
Hi,

I have the following API code that I've been working on:


I'm currently stuck trying to extract the v1 part to its own file, I'd like to re-use the authentication from the external.rb and split out v1 so that if I were to add v2, the file won't grow too big.

I'm kind of new to Roda and am stuck with this, I would appreciate any suggestions.

Thanks in advance.

Diego

Jeremy Evans

não lida,
29 de out. de 2021, 01:05:1229/10/2021
para ruby...@googlegroups.com
The important thing to realize is that the default argument for r.hash_routes is the already matched path.  You can make things easier by making the namespace for your hash routes use the same path. You should be able to do:

# routes/api.rb
hash_branch 'api' do |r|
  r.hash_routes
end

# routes/api/external.rb
hash_branch '/api', 'external' do |r|
  auth_token = ...
  JWT.decode()

  r.hash_routes
end

# routes/api/external/v1.rb
hash_branch '/api/external', 'v1' do |r|
  r.is 'hostesses' do
    # rest of block abbreviated
  end
end

Thanks,
Jeremy


Diego Viola

não lida,
29 de out. de 2021, 01:35:3529/10/2021
para ruby...@googlegroups.com
On Fri, Oct 29, 2021 at 2:05 AM Jeremy Evans <jeremy...@gmail.com> wrote:
>
> On Thu, Oct 28, 2021 at 9:27 PM Diego Viola <diego...@gmail.com> wrote:
>>
>> Hi,
>>
>> I have the following API code that I've been working on:
>>
>> https://gist.github.com/diegoviola/41732846978bf843ad705ce73d0097f6#file-external-rb-L17-L22
>>
>> I'm currently stuck trying to extract the v1 part to its own file, I'd like to re-use the authentication from the external.rb and split out v1 so that if I were to add v2, the file won't grow too big.
>>
>> I'm kind of new to Roda and am stuck with this, I would appreciate any suggestions.
>
>
> The important thing to realize is that the default argument for r.hash_routes is the already matched path. You can make things easier by making the namespace for your hash routes use the same path. You should be able to do:

Makes sense, thank you so much Jeremy. That indeed works.

Diego
Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem