4
好的,我有以下YAML文件,它是使用yaml_db
for Rails生成的。所以這基本上是我的Rails數據庫自動生成的出口:Ruby的YAML只加載第一個來自大文件的記錄,爲什麼?
---
admins:
columns:
- id
- username
- email
- encrypted_password
- password_salt
- sign_in_count
- current_sign_in_at
- last_sign_in_at
- current_sign_in_ip
- last_sign_in_ip
- failed_attempts
- unlock_token
- locked_at
- created_at
- updated_at
records:
- - 1
-
- [email protected]
- $2a$10$dZU50HD6paWS7EjKuWAruOFdwt9eqxiNTRh/D4sj8cqSzy5gjYd2i
- $2a$10$dZU50HD6paWS7EjKuWAruO
- 86
- 2011-01-27 07:37:45 Z
- 2011-01-26 13:27:13 Z
- 12.34.56.78
- 12.34.56.78
- 0
-
-
- 2010-12-23 09:20:46 Z
- 2011-01-27 07:37:45 Z
- - 2
- admin
- [email protected]
- $2a$10$3DML64hdCCvG90bnhIpN/unEEm6C.a9FqGrAFlFHU0.2D54DSQ1Ni
- $2a$10$3DML64hdCCvG90bnhIpN/u
- 1
- 2011-01-21 09:52:14 Z
- 2011-01-21 09:52:14 Z
- 12.34.56.78
- 12.34.56.78
- 0
-
-
- 2011-01-05 14:29:49 Z
- 2011-01-21 09:52:14 Z
---
experiments:
columns:
- id
- description
- startdate
- enddate
- maps_base_URI
- maps_count
- queries_count
- proposals_count
- created_at
- updated_at
.......
現在,當我嘗試加載這個YAML文件在Ruby中有:
file = YAML.load(File.open("data-2011-01-27.yml"))
這不加載超過第一admin
,甚至沒有experiments
:
ruby-1.9.2-p0 > file.keys
=> ["admins"]
ruby-1.9.2-p0 > file["admins"]["records"].count
=> 1
這是爲什麼?我會假設自動生成的.yml文件在語法上是正確的?當我運行rake:db:dump
和rake:db:load
它工作得很好。
指向YAML.load_stream的鏈接不再有效。這是[load_stream]的另一個文檔(http://ruby-doc.org/stdlib-1.9.3/libdoc/psych/rdoc/Psych.html#method-c-load_stream)。 – slothbear 2014-05-26 15:45:38