Sinatra, accessing the environment variable & setting up databases

3,532 views
Skip to first unread message

doug livesey

unread,
Nov 17, 2009, 5:41:01 PM11/17/09
to nwrug-...@googlegroups.com
Hi -- any of the Sinatra buffs out there able to help me with a couple of issues?
I'm wanting to use Datamapper for my models, and *think* I'm okay with that, but I want to be able to set them up for testing, development, and production.
How do I access the environment variable? I mean to set and to get at any given point?
I want to be *very* sure the env is right before I run my cuke features, and that FactoryGirl isn't going to overwrite anything horrible.
Cheers,
   Doug.

Alex Barlow

unread,
Nov 17, 2009, 6:24:19 PM11/17/09
to nwrug-...@googlegroups.com
this may be of interest to you

it covers some ENV variables in sinatra  - http://docs.heroku.com/rack


--

You received this message because you are subscribed to the Google Groups "NWRUG" group.
To post to this group, send email to nwrug-...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nwrug-members?hl=.

doug livesey

unread,
Nov 17, 2009, 6:44:26 PM11/17/09
to nwrug-...@googlegroups.com
Interesting, thankyou.
It doesn't seem to cover where the deployment environment comes from, though.
For example, if you use a configure block, where does the app get the fact that it is in development mode (or test, or production) from?
I've dumped the ENV hash to the console, and still can't see any deployment environment info.
Hmm.
Cheers,
   Doug.

Alex Barlow

unread,
Nov 17, 2009, 6:50:16 PM11/17/09
to nwrug-...@googlegroups.com
Im not sure that is actually available in Sinatra, so same on local as on production really..

I use Sinatra often, for ease, but if you want a full test suite and environments, rails comes into play...

doug livesey

unread,
Nov 18, 2009, 6:18:36 AM11/18/09
to nwrug-...@googlegroups.com
It does have the configure blocks, where you can set app attributes depending on the environment, like so:

configure :development do
  @db_url = "postgres://usr:pwd@localhost"
end

So there must be a mechanism. I'll keep searching!
Cheers,
   Doug.

Adam Holt

unread,
Nov 18, 2009, 8:16:15 AM11/18/09
to nwrug-...@googlegroups.com
Hi Doug

I have just started working with Sinatra over the last week and have come across some of the same issues. I've written up a quick gist for you, though i haven't tested any of it :)


Cheers
Adam

Cheers,
   Doug.

doug livesey

unread,
Nov 18, 2009, 8:45:10 AM11/18/09
to nwrug-...@googlegroups.com
Cheers for that, Adam -- prompted by your gist, I've had a little success with Sinatra::Application.environment() and Sinatra::Application.environment=(), so I'll crack on with that.
Cheers again!
   Doug.

2009/11/18 Adam Holt <ads....@gmail.com>

Adam Holt

unread,
Nov 18, 2009, 8:53:45 AM11/18/09
to nwrug-...@googlegroups.com
No Problem

By the way, the Sinatra Book[1] is a good resource, if you haven't come across it yet, not 100% finished tho

doug livesey

unread,
Nov 18, 2009, 9:18:02 AM11/18/09
to nwrug-...@googlegroups.com
& apparently setting ENV["RACK_ENV"] before anything else will do it, too.

Reply all
Reply to author
Forward
0 new messages