Kris MP Kris MP - 26 days ago 8
Ruby Question

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.

Answer

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.