Can we please get a "raw" loader?
まだ誰も着手していません。
評価
調査の方向性
YAML.load、safe_load、そして提案されているエントリーポイント Psych.set_parse_mode から始め、その後 issue にある 2 つの YAML 例を比較します。raw モードの変換規則と、native-object モードとの違いを定義します。要求された hash-tree 出力が仕様化され、実装テストでカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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"}}]}
- 主要言語
- Ruby
- スター
- 597
- フォーク
- 223
- 平均マージ
- 14分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby/psych のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
Documentation
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 strings対応中かも @Halvanhelv が 31 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
ds-drift
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
we-promise/sure#4120 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
scanaislop/aislop#476 ·
メンテナーはふだん 1 日以内に返信