Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Can we please get a "raw" loader?

Aperta
#286 3 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
ruby, yaml
Ambito
tooling

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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/psych

Tutte le issue di ruby/psych

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.