ruby - Mapping many-to-one in YAML -



ruby - Mapping many-to-one in YAML -

i'm trying introduce many-to-one kind of mapping within yaml configuration file rake.

that is, have like:

- server: address

and i'd have like:

- server: {1, 3, 5: address1; 2, 8, 12: address2}

of course, not right syntax.

this because need different address according given id.

config['server'][3] # should homecoming 'address1' config['server'][5] # should homecoming 'address1' config['server'][12] # , should homecoming 'address2'

is feasibile in way?

thank in advance

it should work way:

create file in config called server_config.yml:

common: &common common_stuff_foo: foo common_stuff_bar: bar server: 1: <<: *common adress: adress_for_server1 2: <<: *common adress: adress_for_server2 ... #some other servers 12: <<: *common adress: adress_for_server12

put file config/initializers config_servers.rb content

config = yaml.load_file("#{rails_root}/config/server_config.yml")

and might address via

config['server'][1]['address'] in application

it's not tested, think work. i'm little bit uncertain numbers in yaml-file

ruby rake yaml

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -