Question regarding :environment plugin

16 views
Skip to first unread message

abhijit nandy

unread,
Jul 14, 2021, 4:39:27 PMJul 14
to Roda
Hi Jeremy,

Is it possible to find the environment inside a route block?

I can use ENV['RACK_ENV'], but I was wondering if the environment plugin makes it any easier!

Code sample below.

class App < Roda
  plugin :environments

  configure :development:production do
    plugin :common_logger
  end

  route do |r|
    r.root do
      # can I find the environment here using the 'environment' plugin?
      'you are on /'
    end
  end
end

Jeremy Evans

unread,
Jul 14, 2021, 7:00:56 PMJul 14
to ruby...@googlegroups.com
Yes.  The environments plugin defines class methods, so you would call the class method to get the environment:

  self.class.environment
 
Thanks,
Jeremy

abhijit nandy

unread,
Jul 15, 2021, 2:28:10 AMJul 15
to ruby...@googlegroups.com
Thank you. 

From: ruby...@googlegroups.com <ruby...@googlegroups.com> on behalf of Jeremy Evans <jeremy...@gmail.com>
Sent: Thursday, July 15, 2021 4:30:44 AM
To: ruby...@googlegroups.com <ruby...@googlegroups.com>
Subject: Re: [ruby-roda] Question regarding :environment plugin
 
--
You received this message because you are subscribed to the Google Groups "Roda" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-roda+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-roda/CADGZSScx%2BdCCdSYBmDqRGjHt1oq_LRPMFsQYxNnLuugRtEuaiw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages