Sylar
Sylar

Reputation: 12092

How to configure a sinatra rack app to use figaro

I saw this post and think something is missing or a change in version. I have a very simple rack app using figaro -- hosted with Heroku. Currently, Im on local machine.

I now need to use ENV.

My app structure:

APP
 |_ config/
 |_ public/
 |_ views/
 |_ config.ru
 |_ app.rb
 |_ other-files

Inside config/application.yml

SOME_KEY: some-value

Inside config.ru

require './app.rb'
run MyApp.run!

This the part this gives the error. Inside app.rb:

require  File.dirname(__FILE__) + '/config/application.yml'

[...]

This is the same line as in the link above. I get

cannot load such file /config/application.yml

In app.rb, I need to be able to do ENV['SOME_KEY']

Upvotes: 0

Views: 289

Answers (2)

mahemoff
mahemoff

Reputation: 46479

I've done this before in a standalone app as follows:

Figaro.application = Figaro::Application.new(
  environment: 'production',
  path: File.expand_path("config/application.yml")
)
Figaro.load

Upvotes: 1

lacostenycoder
lacostenycoder

Reputation: 11226

You can't just require a yaml file as it is not ruby. Yaml is a file structure that is not ruby specific. Figaro was also written to be used with Ruby on Rails, not Sinatra. You can probably figure out a way to make it work, but it's not as easy as just loading a yaml config file.

See this post for some ideas of how you might accomplish what you're trying to do. Here is a forked version of the gem which might work for you.

https://github.com/laserlemon/figaro/pull/229

Upvotes: 0

Related Questions