Re: Loading, CGI and some aother questions

Well, configs are mine anyway, so I’m not afraid of injection from those
files. But how do I “source” a file? Kernel#load and Kernel#require
return boolean and do not seem to affect local scope. Could you please
provide a code example?

----- Original Message ----

The sourcing a .rb file is more flexible, however you risk code
injection that way. Usual considerations apply.

David V.

On Sun, 12 Nov 2006, Gambler Gluck wrote:

Well, configs are mine anyway, so I’m not afraid of injection from those
files. But how do I “source” a file? Kernel#load and Kernel#require return
boolean and do not seem to affect local scope. Could you please provide a
code example?

eval IO.read(config)

it’s evil - pure evil. i’d use yaml if possible.

-a

Gambler Gluck wrote:

Well, configs are mine anyway, so I’m not afraid of injection from those files. But how do I “source” a file? Kernel#load and Kernel#require return boolean and do not seem to affect local scope. Could you please provide a code example?

eval / instance_eval / class_eval the contents of the file instead. You
could also do as Rails does in for example config/routes.rb and provide
an API to configure your app in a singleton. (Even is singletons are
slightly evil with respects to unit testing, configuration isn’t a
component whose state changes at runtime as part of regular operation -
i.e. only explicitly, not as a business logic side effect, so you can
probably get away with that approach.)

David V.