The Ruby/ERB way to do this?

Hello, I was wondering if someone could point me to a smarter way of
doing
the following? It’s probably a Ruby basics question.

I am using ERB to generate sets of configuration files for different
environments. I imagined that I would use a different config file per
environment, that sets variables, and apply this against a list of
configuration file templates.

Currently each environment file defines a module “X” that has constants
for
each variable:
module X
MgrPort = ‘3000’
MsgPort2s = ‘4000’

The template files reference the variables like so
domain = <%= X::Domain %>

The script that calls erb.result() uses require/include to reference the
config file

require “Configs/stagingProperties”
include X

There must be a better way to do this. Is there a “Right Way” here? I’ve
perused the erb docs and the Pickaxe book but neither explicitly join
the
dots.


The information contained in and accompanying this communication is
strictly
confidential and intended solely for the use of the intended
recipient(s).
If you have received it by mistake please let us know by reply and then
delete it from your system; you should not copy the message or disclose
its
content to anyone.
MarketAxess reserves the right to monitor the content of emails sent to
or
from its systems.
Any comments or statements made are not necessarily those of
MarketAxess.
For more information, please visit www.marketaxess.com. MarketAxess
Europe
Limited is regulated in the UK by the FSA, registered in England no.
4017610, registered office at 71 Fenchurch Street, London, EC3M 4BS.
Telephone (020) 7709 3100.
MarketAxess Corporation is regulated in the USA by the SEC and the NASD,
incorporated in Delaware, executive offices at 140 Broadway, New York,
NY
10005. Telephone (1) 212 813 6000.

Not sure if I totally understand your question, but I’ll try to help.

Note that if you want to, you can make your require use a variable so
that
you can vary which file to require in.

Also note that you can do your require and include in the module that
calls
erb since you can pass in a binding. The binding gives erb access to
everything that was available where ever the binding was created. So you
don’t have to put the require and inlude in the erb template.