简体   繁体   中英

Rails modify only specifi key on yaml file

I have this yaml file in my rails app:

common: &common
  host: 'api.example.com'
  social_media:
    secret: 'omglolthisissecret'
  snap:
    host: "https://app.example.com/money/v1/transactions"

development:
  <<: *common

test:
  <<: *common

production:
  <<: *common

I need to set different value for snap.host key, let say the value should be:

https://sandbox.example.com/money/v1/transactions

How do I do that? thanks in advance.

Why putting it to defaults if that's changing for environments? :)

Anyway, to override a value you should, well, override it:

common: &common
  host: 'api.example.com'
  social_media:
    secret: 'omglolthisissecret'
  snap:
    host: "https://app.example.com/money/v1/transactions"

development:
  <<: *common
  snap:
    host: 'devhost'

test:
  <<: *common
  snap:
    host: 'testhost'

production:
  <<: *common
  snap:
    host: 'prodhost'

Note : If snap contains other fields in defaults, such override would delete them, so while overriding you have to repeat all fields.

Override it in desired environment

common: &common
  host: 'api.example.com'
  social_media:
    secret: 'omglolthisissecret'
  snap:
    host: "https://app.example.com/money/v1/transactions"

development:
  <<: *common
  snap:
    host: "https://sandbox.example.com/money/v1/transactions"

test:
  <<: *common
  snap:
    host: "https://sandbox.example.com/money/v1/transactions"

production:
  <<: *common

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM