Use Symbols from yaml file

9 views
Skip to first unread message

George Bray

unread,
Jan 17, 2008, 1:16:55 AM1/17/08
to rubyonra...@googlegroups.com
I'm loading application-wide variables from a yaml file, and one of
them is a symbol

development:
LDAP_HOST: 'ldap.x.edu.au'
LDAP_PORT: '636'
LDAP_ENC: ':simple_tls'
...

That works fine, and I use the vars like this:

ldap_con = Net::LDAP.new(
:host => APP_CONFIG['LDAP_HOST'],
:port => APP_CONFIG['LDAP_PORT'],
:encryption => {:method => eval(APP_CONFIG['LDAP_ENC'].to_s)}
)

Converting the third variable LDAP_ENC to a string, then evaluating it
looks ugly. Is there a better way to draw on symbols from a yaml
file?

Or how about a syntax to dynamically specify the name of the symbol if
what's stored in the yaml file is just

LDAP_ENC: 'simple_tls'

thanks!
--
George Bray, The Australian National University, Canberra, Australia.

Aaron

unread,
Jan 17, 2008, 1:36:39 AM1/17/08
to Ruby on Rails: Talk
> Converting the third variable LDAP_ENC to a string, then evaluating it
> looks ugly.  Is there a better way to draw on symbols from a yaml
> file?

You can put the unquoted symbol right into the yaml file:

LDAP_ENC: :simple_tls

Aaron

Reply all
Reply to author
Forward
0 new messages