[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

YAML config files with environment specific settings

Calvin Nguyen

3/21/2009 2:21:00 AM

I need to store settings by environment but started off simply with my
config file at: \config\config.yml. The only setting I had was this:
attachment_volume: \\attach\transfers

With this, cod I'm able to load the file within my initializer and
reference it just fine from calling code within an ActiveRecord model
class. So far so good.

Since this setting is a server location that varies by environment, I
tried to use the by-environment structure and changed my config file to
this:
development:
attachment_volume: \\attach\transfers

test:
attachment_volume: \\attach\test\transfers

I get the following error during that indicates it didn't like the
second instance of the colon on the second line. Here is the real
error: Uncaught exception: syntax error on line 1, col 20: `
attachment_volume:
\\atlas\transfer\greenlight\predevelopment\attachments'

Here is full error stack:

Exiting C:/Ruby/lib/ruby/1.8/yaml.rb:133:in `load'
C:/Ruby/lib/ruby/1.8/yaml.rb:133:in `load'
C:/Ruby/lib/ruby/1.8/yaml.rb:144:in `load_file'
C:/Ruby/lib/ruby/1.8/yaml.rb:143:in `open'
C:/Ruby/lib/ruby/1.8/yaml.rb:143:in `load_file'
C:/TFS/GreenLight/DEV/server/config/initializers/load_config.rb:2
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
`load_without_new_constant_marking'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
`load'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in
`new_constants_in'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
`load'
./script/../config/../vendor/rails/railties/lib/initializer.rb:550:in
`load_application_initializers'
./script/../config/../vendor/rails/railties/lib/initializer.rb:549:in
`each'
./script/../config/../vendor/rails/railties/lib/initializer.rb:549:i
n `load_application_initializers'
./script/../config/../vendor/rails/railties/lib/initializer.rb:167:in
`process'
./script/../config/../vendor/rails/railties/lib/initializer.rb:112:in
`send'
./script/../config/../vendor/rails/railties/lib/initializer.rb:112:in
`run'
C:/TFS/GreenLight/DEV/server/config/environment.rb:16
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in
`require'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in
`new_constants_in'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in
`require'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/../lib/mongrel/rails.rb:147:in
`rails'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:113:in
`cloaker_'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:149:in
`call'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:149:in
`listener'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:99:in
`cloaker_'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:50:in
`call'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:50:in
`initialize'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:84:in
`new'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:84:in
`run'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/command.rb:212:in
`run'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:281
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
`load_without_new_constant_marking'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
`load'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in
`new_constants_in'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
`load'
C:/TFS/GreenLight/DEV/server/vendor/rails/railties/lib/commands/servers/mongrel.rb:64
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in
`require'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in
`new_constants_in'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in
`require'
C:/TFS/GreenLight/DEV/server/vendor/rails/railties/lib/commands/server.rb:49
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
./script/server:3
C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/lib/ruby-debug.rb:101:in
`debug_load'
C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/lib/ruby-debug.rb:101:in
`debug_program'
C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/bin/rdebug-ide:82
C:\Ruby\bin\rdebug-ide:19:in `load'
C:\Ruby\bin\rdebug-ide:19
-e:2:in `load'
-e:2
Uncaught exception: syntax error on line 1, col 20: `
attachment_volume:
\\atlas\transfer\greenlight\predevelopment\attachments'

Has anyone been able to get the by environment structure load to work?
Please advise? Thanks in advance.
--
Posted via http://www.ruby-....

3 Answers

Phlip

3/21/2009 2:30:00 AM

0

Calvin Nguyen wrote:
> I need to store settings by environment but started off simply with my
> config file at: \config\config.yml. The only setting I had was this:
> attachment_volume: \\attach\transfers
>
> With this, cod I'm able to load the file within my initializer and
> reference it just fine from calling code within an ActiveRecord model
> class. So far so good.
>
> Since this setting is a server location that varies by environment, I
> tried to use the by-environment structure and changed my config file to
> this:
> development:
> attachment_volume: \\attach\transfers
>
> test:
> attachment_volume: \\attach\test\transfers
>
> I get the following error during that indicates it didn't like the
> second instance of the colon on the second line. Here is the real
> error: Uncaught exception: syntax error on line 1, col 20: `
> attachment_volume:
> \\atlas\transfer\greenlight\predevelopment\attachments'
>
> Here is full error stack:
>
> Exiting C:/Ruby/lib/ruby/1.8/yaml.rb:133:in `load'
> C:/Ruby/lib/ruby/1.8/yaml.rb:133:in `load'
> C:/Ruby/lib/ruby/1.8/yaml.rb:144:in `load_file'
> C:/Ruby/lib/ruby/1.8/yaml.rb:143:in `open'
> C:/Ruby/lib/ruby/1.8/yaml.rb:143:in `load_file'
> C:/TFS/GreenLight/DEV/server/config/initializers/load_config.rb:2
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
> `load_without_new_constant_marking'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
> `load'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in
> `new_constants_in'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
> `load'
> ./script/../config/../vendor/rails/railties/lib/initializer.rb:550:in
> `load_application_initializers'
> ./script/../config/../vendor/rails/railties/lib/initializer.rb:549:in
> `each'
> ./script/../config/../vendor/rails/railties/lib/initializer.rb:549:i
> n `load_application_initializers'
> ./script/../config/../vendor/rails/railties/lib/initializer.rb:167:in
> `process'
> ./script/../config/../vendor/rails/railties/lib/initializer.rb:112:in
> `send'
> ./script/../config/../vendor/rails/railties/lib/initializer.rb:112:in
> `run'
> C:/TFS/GreenLight/DEV/server/config/environment.rb:16
> C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
> `gem_original_require'
> C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
> `require'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in
> `require'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in
> `new_constants_in'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in
> `require'
> C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/../lib/mongrel/rails.rb:147:in
> `rails'
> C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:113:in
> `cloaker_'
> C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:149:in
> `call'
> C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:149:in
> `listener'
> C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:99:in
> `cloaker_'
> C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:50:in
> `call'
> C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:50:in
> `initialize'
> C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:84:in
> `new'
> C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:84:in
> `run'
> C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/command.rb:212:in
> `run'
> C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:281
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
> `load_without_new_constant_marking'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
> `load'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in
> `new_constants_in'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
> `load'
> C:/TFS/GreenLight/DEV/server/vendor/rails/railties/lib/commands/servers/mongrel.rb:64
> C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
> `gem_original_require'
> C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
> `require'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in
> `require'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in
> `new_constants_in'
> C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in
> `require'
> C:/TFS/GreenLight/DEV/server/vendor/rails/railties/lib/commands/server.rb:49
> C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
> `gem_original_require'
> C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
> `require'
> ./script/server:3
> C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/lib/ruby-debug.rb:101:in
> `debug_load'
> C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/lib/ruby-debug.rb:101:in
> `debug_program'
> C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/bin/rdebug-ide:82
> C:\Ruby\bin\rdebug-ide:19:in `load'
> C:\Ruby\bin\rdebug-ide:19
> -e:2:in `load'
> -e:2
> Uncaught exception: syntax error on line 1, col 20: `
> attachment_volume:
> \\atlas\transfer\greenlight\predevelopment\attachments'
>
> Has anyone been able to get the by environment structure load to work?
> Please advise? Thanks in advance.

Phlip

3/21/2009 2:32:00 AM

0

> error: Uncaught exception: syntax error on line 1, col 20: `
> attachment_volume:
> \\atlas\transfer\greenlight\predevelopment\attachments'

Is that a transmission error, or does \\atlas really start in the first text
column? directly under the 'a' in attachment?

Put it on the same line as volume:.

Next, in terms of style, you should use / if at all possible. MS's experiment
with \ has failed, and even their own tools respect /.

Calvin Nguyen

3/21/2009 3:26:00 AM

0

Phlip wrote:
>> error: Uncaught exception: syntax error on line 1, col 20: `
>> attachment_volume:
>> \\atlas\transfer\greenlight\predevelopment\attachments'
>
> Is that a transmission error, or does \\atlas really start in the first
> text
> column? directly under the 'a' in attachment?
>
> Put it on the same line as volume:.
>
> Next, in terms of style, you should use / if at all possible. MS's
> experiment
> with \ has failed, and even their own tools respect /.

That's a transmission error. Strange thing I just realized for me ( on
windows) if i remove all whitespace, then the YAML config file load
succeeds but my APP_CONFIG structure that loads up is nil. Here is how
I'm loading up my hash:
APP_CONFIG =
YAML.load_file("#{RAILS_ROOT}/config/config.yaml")[RAILS_ENV]

when i excecute this, the exception is thrown: self.volume =
APP_CONFIG['attachment_volume']
What am I missing?
--
Posted via http://www.ruby-....