尝试在Ruby中打开我的Yaml文件时出现上述错误。我已经在此验证器中检查了YAML,它已通过http://yamllint.com/。我不确定我的YAML会阻止它打开是什么问题。有任何想法吗?这是YAML文件。我正在尝试使用yml = YAML::load(File.open('servers.yml'))
---
servers:
- ps-overture-d01
location: ps-overture-d01
tomcat_location: /home/tomcat/tomcat/webapps/report/
user: tomcat
menus:
- Accounts Receivable
reports:
- Accounts Receivable Aging Report
name: AccountsReceivableAgingReport
location: /public/Common/Reports/Accounts_Receivable_Reports
- Inventory
reports:
- Inventory Master List Report
name: InventoryMasterListReport
location: /public/Common/Reports/Inventory_Reports
- Inventory Totals Report
name: InventoryTotalsReport
location: /public/Common/Reports/Inventory_Reports
- Dealer Purchasing Report
name: DealerPurchasingReport
location: /public/Common/Reports/Inventory_Reports
- DOA Report
name: DOAReport
location: /public/Common/Reports/Inventory_Reports
- Stock Transfers Report
name: StockTransfersReport
location: /public/Common/Reports/Inventory_Reports
- Removed Inventory Report
name: RemovedInventoryReport
location: /public/Common/Reports/Inventory_Reports
- Inventory Order Sheet Report
name: InventoryOrderSheetReport
location: /public/Common/Reports/Inventory_Reports
- Inventory Totals GMROI Report
name: InventoryTotalsGMROIReport
location: /public/Common/Reports/Inventory_Reports
- Master Inventory GMROI Report
name: MasterInventoryGMROIReport
location: /public/Common/Reports/Inventory_Reports
- Dead Stock Report
name: DeadInventoryReport
location: /public/Common/Reports/Inventory_Reports
- Dead Stock Report Details
name: DeadInventoryReportDetails
location: /public/Common/Reports/Inventory_Reports
- Negative Quantity Report
name: NegativeInventoryQTYReport
location: /public/Common/Reports/Inventory_Reports
答案 0 :(得分:10)
你的问题在于没有冒号的行:
- ps-overture-d01
location: ps-overture-d01
http://yamllint.com/的作用是将它们连接到下一行:
? "ps-overture-d01 location"
: ps-overture-d01
Ruby的YAML库不会这样做,但会引发错误。我不确定你是否打算将这些行连接起来,所以你需要看看如何正确调整YAML以给出一个合理的结构,或许可以为每一行添加id:
?
- id: ps-overture-d01
location: ps-overture-d01
以下是您的示例,我建议进行更改:
---
servers:
- id: ps-overture-d01
location: ps-overture-d01
tomcat_location: /home/tomcat/tomcat/webapps/report/
user: tomcat
menus:
- id: Accounts Receivable
reports:
- id: Accounts Receivable Aging Report
name: AccountsReceivableAgingReport
location: /public/Common/Reports/Accounts_Receivable_Reports
- id: Inventory
reports:
- id: Inventory Master List Report
name: InventoryMasterListReport
location: /public/Common/Reports/Inventory_Reports
- id: Inventory Totals Report
name: InventoryTotalsReport
location: /public/Common/Reports/Inventory_Reports
- id: Dealer Purchasing Report
name: DealerPurchasingReport
location: /public/Common/Reports/Inventory_Reports
- id: DOA Report
name: DOAReport
location: /public/Common/Reports/Inventory_Reports
- id: Stock Transfers Report
name: StockTransfersReport
location: /public/Common/Reports/Inventory_Reports
- id: Removed Inventory Report
name: RemovedInventoryReport
location: /public/Common/Reports/Inventory_Reports
- id: Inventory Order Sheet Report
name: InventoryOrderSheetReport
location: /public/Common/Reports/Inventory_Reports
- id: Inventory Totals GMROI Report
name: InventoryTotalsGMROIReport
location: /public/Common/Reports/Inventory_Reports
- id: Master Inventory GMROI Report
name: MasterInventoryGMROIReport
location: /public/Common/Reports/Inventory_Reports
- id: Dead Stock Report
name: DeadInventoryReport
location: /public/Common/Reports/Inventory_Reports
- id: Dead Stock Report Details
name: DeadInventoryReportDetails
location: /public/Common/Reports/Inventory_Reports
- id: Negative Quantity Report
name: NegativeInventoryQTYReport
location: /public/Common/Reports/Inventory_Reports