Can we please get a "raw" loader?
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Inizia con YAML.load, safe_load e il punto di ingresso proposto Psych.set_parse_mode, quindi confronta i due esempi YAML nell’issue. Definisci le regole di conversione della modalità raw e in che modo dovrebbe differire dalla modalità oggetti nativi; il lavoro è completato quando l’output hash-tree richiesto è specificato e coperto da test di implementazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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"}}]}
- Lingua principale
- Ruby
- Stelle
- 597
- Fork
- 223
- Merge medio
- 6h 8m
- PR unite (30g)
- 2
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ruby/psych
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 stringsForse già presa @Halvanhelv l’ha presa 30 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
zerocracy/judges-action#2743 ·
I maintainer di solito rispondono entro 8 giorni
-
Add Nagoya Ruby Kaigi 05Apertacontent good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
rubyevents/rubyevents#2182 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
TarteelAI/quranic-universal-library#821 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Homebrew/homebrew-cask#293134 ·
I maintainer di solito rispondono entro 1 giorno