In Sinatra/Padrino where is a sensible place to add constants for use inside routes?
I'm using Padrino to mount multiple apps so I want the constants available to all apps. (All apps inherit from a base class.)
I've used Sinatra.helpers to add methods for use inside routes.
I was hoping for a similar approach for constants.
Update
This appears to be a scoping issue, but I can't figure out what's wrong in this scenario.
Here is a stripped down padrino app which demonstrates the problem:
app.rb
class MyProject < Padrino::Application
register Padrino::Rendering
register Padrino::Mailer
register Padrino::Helpers
MY_CONST = 123
end
controllers.rb
MyProject.controller do
get "/" do
p self.class # => MyProject
p self.class.constants # => [:DATA_ATTRIBUTES, ... <snip>..., :MY_CONST, ... <snip>... ]
p MyProject::MY_CONST # => 123
p MY_CONST # => NameError - uninitialized constant MY_CONST
end
end