setting Ramaze.options.mode

126 views
Skip to first unread message

Roy Wright

unread,
Mar 10, 2012, 3:38:01 PM3/10/12
to Ramaze
Howdy!

What's your preferred method for setting Ramaze.options.mode for the
different runtime environments?

Basically the issue I'm looking at is using different database
connections for :dev, :live, and :test (also used for defining
middleware). I'm wanting to select the connection in app.rb before
requiring my models. The Ramaze.options.mode defaults to :dev. I can
set it to :test in my spec/spec_helper.rb and features/support/env.rb
before requiring app.rb. But how should I handle live deployments?

TIA,
Roy


Yorick Peterse

unread,
Mar 10, 2012, 4:41:31 PM3/10/12
to ram...@googlegroups.com
Roy,

One way of doing this is by setting the mode in an environment
specific configuration file. For example, I typically create a config/
directory that contains a file config.rb. This file sets generic
configuration options such as the mode of Ramaze, what cache adapter to
use (for sessions and the like) and so on. In essence this would come
down to the following code for your app.rb file:

require 'ramaze'

require __DIR__('config/config')
require __DIR__('config/database')

# etc.

Yorick

signature.asc

Roy Wright

unread,
Mar 10, 2012, 4:55:57 PM3/10/12
to Ramaze
Thank you! I'll give that a shot.

Stas Sușcov

unread,
Mar 10, 2012, 5:00:45 PM3/10/12
to ram...@googlegroups.com
I have something like this in my app.rb
(A more extended version of what Yorick presented already.)

---
if ENV['APP_ENV'] == 'production'
Ramaze.options.mode = :live
end

if Ramaze.options.mode == :live
require __DIR__('config/live')
else
require __DIR__('config/dev')
end
Ramaze::Log.info('We start in %s mode' % Ramaze.options.mode.to_s)
---

This can be extended to include :test too.
Also, you can use RACK_ENV if you really want.

În data de Sat, 10 Mar 2012 23:55:57 +0200, Roy Wright
<roywr...@gmail.com> a scris:

Michel Blanc

unread,
Mar 11, 2012, 12:42:59 PM3/11/12
to ram...@googlegroups.com
On 10/03/2012 23:00, Stas Sușcov wrote:
> I have something like this in my app.rb
> (A more extended version of what Yorick presented already.)
>
> ---
> if ENV['APP_ENV'] == 'production'
> Ramaze.options.mode = :live
> end
>

Roy,

You can find an approach similar to Sta's one here :
https://github.com/mwlang/cashmere/blob/master/environment.rb

There are many other interesting bits in this project, regarding testing
(auth Mocking in app.rb), tasks and specs.

Bye,

M
--
Michel Blanc - netWorks
8A68 0871 747A 65B6 E87C 3BEA 187C 36BB 2CE5 68BD

Reply all
Reply to author
Forward
0 new messages