繁体   English   中英

Rails仅修改yaml文件上的特定键

[英]Rails modify only specifi key on yaml file

我在我的rails应用程序中有这个yaml文件:

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

我需要为snap.host键设置不同的值,假设值应为:

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

我怎么做? 提前致谢。

如果环境发生变化,为什么要将其置于默认值? :)

无论如何,要覆盖一个值,你应该覆盖它:

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'

注意 :如果snap包含默认值中的其他字段,则此类覆盖会删除它们,因此在覆盖时必须重复所有字段。

在期望的环境中覆盖它

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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