Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Can we please get a "raw" loader?

Đang mở
#286 3 bình luận 3 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
ruby, yaml
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu với YAML.load, safe_load và entry point được đề xuất Psych.set_parse_mode, sau đó so sánh hai ví dụ YAML trong issue. Xác định các quy tắc chuyển đổi của raw mode và cách nó phải khác với native-object mode; được xem là hoàn tất khi đầu ra hash-tree được yêu cầu đã được đặc tả và được bao phủ bởi các bài kiểm thử triển khai.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

There are times when we need to load a YAML file but for various reasons, we do not want or care about the serialization/native dataclass conversions. We want to load the data in as a hash-tree object, as if the object classifier were not there.

Now it seems to me based on the long discussion related to the safe_load method, that safe_load does not, in fact, do what is requested here. It seems to me that several sane voices were a bit shuoted down in that discussion. But whatever.

What is needed is essentially to load YAML files as if they were dumb JSON files. As if the following code were implemented before the #load

yamltext = File.read("somefile","r")
yamltext.sub!(/^--- \!.*$/,'---')
purehash = YAML.load(yamltext)

Given the following YAML:

--- !ruby/object:Some::Custom::Type::User::Has::No::Gem::For
 node: "string"
 array:
  - "string"
  - unquoted text
  - "12.5"
  - 12.5
  - subarray:
      option: true
      nottrue: "false"

We get back from #load:

{"node"=>"string", "array"=>["string", "unquoted text", "12.5", 12.5, {"subarray"=>{"option"=>true, "nottrue"=>"false"}}]}

I propose an implementation that is cleaner, that uses YAML.load() but based on the parser-personality. The personalities might be a kind of a "raw" mode and "native-object" mode. Raw mode only sees Hash, Array, String. Native-object mode also sees numeric, boolean (and..?)

Psych.set_parse_mode(:native_object_conversion)
purehash=YAML.load(yamltext)

Produces the inspected output, above. Whereas:

Psych.set_parse_mode(:no_object_conversion)
purehash=YAML.load(yamltext)

produces (subtly different):

{"node"=>"string", "array"=>["string", "unquoted text", "12.5", "12.5", {"subarray"=>{"option"=>"true", "nottrue"=>"false"}}]}
Ngôn ngữ chính
Ruby
Star
597
Fork
223
Merge trung bình
14 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ruby/psych

Tất cả issue của ruby/psych

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.