Here is what I do, because of the order in which configure blocks are
called n sinatra, and because it doesn't work in tests:
def db_config
Yaml.load_file('path/to/database.yml').to_mash
end
def setup_db(env)
DataMapper::Logger.new("log/#{env}.log", {:development
=> :debug, :production => :info}[env])
DataMapper.setup(:default, db_config[env])
end
configure :development do
setup_db(:development)
end
# ^ same thing for production/test
On Mar 4, 6:50 am, Carl Youngblood <[email protected]> wrote:
> I'm working with a sinatra app and I want to declare multiple
> datamapper repositories and choose which one should be the default
> based on whether my app is running in development or production mode.
> Here is my code:
>
> DataMapper.setup(:development, "sqlite3://#{$ROOT_DIR}/dev.db")
> DataMapper.setup(:production, {
> :adapter => 'mysql',
> :host => 'localhost',
> :username => 'XXXXXXXXXX',
> :password => 'XXXXXXXXXX',
> :database => 'pacman_production'})
>
> configure :development do
> DataMapper::Logger.new(STDOUT, :debug)
> DataMapper.setup(:default, repository(:development).adapter.options)
> end
> configure :production do
> DataMapper.setup(:default, repository(:production).adapter.options)
> end
>
> This works, but is this syntax a good way of doing it, or does anyone
> have a better suggestion?
>
> My reason for wanting both repos is so that I can copy data in between them.
>
> Thanks,
> Carl
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.