Can we please get a "raw" loader?
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
Beginne mit YAML.load, safe_load und dem vorgeschlagenen Einstiegspunkt Psych.set_parse_mode und vergleiche anschließend die beiden YAML-Beispiele im Issue. Definiere die Konvertierungsregeln des Raw-Modus und wie er sich vom Native-Object-Modus unterscheiden soll; erledigt bedeutet, dass die angeforderte Hash-Tree-Ausgabe spezifiziert und durch Implementierungstests abgedeckt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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"}}]}
- Vorherrschende Sprache
- Ruby
- Sterne
- 596
- Forks
- 224
- Ø Merge
- 5 Std. 50 Min.
- Gemergte PRs (30 T.)
- 3
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus ruby/psych
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Documentation
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 stringsEvtl. vergeben @Halvanhelv hat das vor 38 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 55/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 68/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
Ähnliche Issues
-
Windows: packaged_agent_ruby? never matches 'Puppet Labs\Puppet', so the openvox gem is not foundOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
-
Falha nos links do postOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
temporalio/sdk-ruby#625 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 94/100
zerocracy/judges-action#2803 ·
Maintainer antworten meist innerhalb von 5 Tagen
-
empty tone.rbOffen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100