How should I handle config files with Sinatra?

641 views
Skip to first unread message

Kurt Mackey

unread,
Jul 30, 2008, 11:01:50 AM7/30/08
to sinatrarb
I've been digging around, but can't seem to find the "blessed" way of
specifying configuration settings for Sinatra apps. Has anyone
written a blog post or anything about that?

Damon Clinkscales

unread,
Jul 30, 2008, 11:09:13 AM7/30/08
to sina...@googlegroups.com

Kurt,

Not sure if this is blessed or not, but I just do:

configure do
load_config "./config.yml"
end

def load_config(file)
if File.exist?(file)
yaml = YAML.load_file(file)
ENV['SOMETHING'] = yaml['something']
end
end

If there is a better way, I'd love to hear.

-damon

--
http://twitter.com/damon

Blake Mizerany

unread,
Jul 30, 2008, 2:34:12 PM7/30/08
to sina...@googlegroups.com
You can use Sinatra's built in options Hash:

configure do
  set :myopt => 'foo',
        :another => 'bar'
end

get '/' do
  x = Sinatra.options[:myopt]
  ...
end
--
Blake Mizerany
blake.m...@gmail.com
Reply all
Reply to author
Forward
0 new messages