Yaml-full-length-example

提供:Dev Guides
移動先:案内検索

YAML-完全な長さの例

The following full-length example specifies the construct of YAML which includes symbols and various representations which will be helpful while converting or processing them in JSON format. These attributes are also called as key names in JSON documents. These notations are created for security purposes.

上記のYAML形式は、デフォルト、アダプター、およびホストのさまざまな属性を、さまざまな他の属性とともに表します。 YAMLはまた、生成されたすべてのファイルのログを保持し、生成されたエラーメッセージの追跡を維持します。 指定されたYAMLファイルをJSON形式に変換すると、次のように目的の出力が得られます-

defaults: &defaults
   adapter:  postgres
   host:     localhost

development:
   database: myapp_development
   <<: *defaults

test:
   database: myapp_test
   <<: *defaults

YAMLをJSON形式に変換して、出力を確認しましょう。

{
   "defaults": {
      "adapter": "postgres",
      "host": "localhost"
   },
   "development": {
      "database": "myapp_development",
      "adapter": "postgres",
      "host": "localhost"
   },
   "test": {
      "database": "myapp_test",
      "adapter": "postgres",
      "host": "localhost"
   }
}

プレフィックス「<<:*」が付いたデフォルトキーは、同じコードスニペットを繰り返し記述する必要がなく、必要に応じて含まれます。