psych 5.1.2 → 5.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Psych
4
4
  # The version of Psych you are using
5
- VERSION = '5.1.2'
5
+ VERSION = '5.2.3'
6
6
 
7
7
  if RUBY_ENGINE == 'jruby'
8
- DEFAULT_SNAKEYAML_VERSION = '2.7'.freeze
8
+ DEFAULT_SNAKEYAML_VERSION = '2.9'.freeze
9
9
  end
10
10
  end
@@ -36,7 +36,7 @@ module Psych
36
36
 
37
37
  unless @domain_types.empty? || !target.tag
38
38
  key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:')
39
- key = "tag:#{key}" unless key =~ /^(?:tag:|x-private)/
39
+ key = "tag:#{key}" unless key.match?(/^(?:tag:|x-private)/)
40
40
 
41
41
  if @domain_types.key? key
42
42
  value, block = @domain_types[key]
@@ -79,7 +79,6 @@ module Psych
79
79
  class_loader.big_decimal._load o.value
80
80
  when "!ruby/object:DateTime"
81
81
  class_loader.date_time
82
- require 'date' unless defined? DateTime
83
82
  t = @ss.parse_time(o.value)
84
83
  DateTime.civil(*t.to_a[0, 6].reverse, Rational(t.utc_offset, 86400)) +
85
84
  (t.subsec/86400)
@@ -17,19 +17,15 @@ module Psych
17
17
  def initialize
18
18
  @obj_to_id = {}.compare_by_identity
19
19
  @obj_to_node = {}.compare_by_identity
20
- @targets = []
21
20
  @counter = 0
22
21
  end
23
22
 
24
23
  def register target, node
25
- @targets << target
26
24
  @obj_to_node[target] = node
27
25
  end
28
26
 
29
27
  def key? target
30
28
  @obj_to_node.key? target
31
- rescue NoMethodError
32
- false
33
29
  end
34
30
 
35
31
  def id_for target
@@ -69,6 +65,7 @@ module Psych
69
65
  fail(ArgumentError, "Invalid line_width #{@line_width}, must be non-negative or -1 for unlimited.")
70
66
  end
71
67
  end
68
+ @stringify_names = options[:stringify_names]
72
69
  @coders = []
73
70
 
74
71
  @dispatch_cache = Hash.new do |h,klass|
@@ -264,20 +261,20 @@ module Psych
264
261
  style = Nodes::Scalar::LITERAL
265
262
  plain = false
266
263
  quote = false
267
- elsif o =~ /\n(?!\Z)/ # match \n except blank line at the end of string
264
+ elsif o.match?(/\n(?!\Z)/) # match \n except blank line at the end of string
268
265
  style = Nodes::Scalar::LITERAL
269
266
  elsif o == '<<'
270
267
  style = Nodes::Scalar::SINGLE_QUOTED
271
268
  tag = 'tag:yaml.org,2002:str'
272
269
  plain = false
273
270
  quote = false
274
- elsif o == 'y' || o == 'n'
271
+ elsif o == 'y' || o == 'Y' || o == 'n' || o == 'N'
275
272
  style = Nodes::Scalar::DOUBLE_QUOTED
276
273
  elsif @line_width && o.length > @line_width
277
274
  style = Nodes::Scalar::FOLDED
278
- elsif o =~ /^[^[:word:]][^"]*$/
275
+ elsif o.match?(/^[^[:word:]][^"]*$/)
279
276
  style = Nodes::Scalar::DOUBLE_QUOTED
280
- elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/ =~ o
277
+ elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/.match?(o)
281
278
  style = Nodes::Scalar::SINGLE_QUOTED
282
279
  end
283
280
 
@@ -327,7 +324,7 @@ module Psych
327
324
  if o.class == ::Hash
328
325
  register(o, @emitter.start_mapping(nil, nil, true, Psych::Nodes::Mapping::BLOCK))
329
326
  o.each do |k,v|
330
- accept k
327
+ accept(@stringify_names && Symbol === k ? k.to_s : k)
331
328
  accept v
332
329
  end
333
330
  @emitter.end_mapping
@@ -340,7 +337,7 @@ module Psych
340
337
  register(o, @emitter.start_mapping(nil, '!set', false, Psych::Nodes::Mapping::BLOCK))
341
338
 
342
339
  o.each do |k,v|
343
- accept k
340
+ accept(@stringify_names && Symbol === k ? k.to_s : k)
344
341
  accept v
345
342
  end
346
343
 
data/lib/psych.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
+ require 'date'
3
+
2
4
  require_relative 'psych/versions'
3
5
  case RUBY_ENGINE
4
6
  when 'jruby'
@@ -84,7 +86,7 @@ require_relative 'psych/class_loader'
84
86
  # Psych.safe_load_file("data.yml", permitted_classes: [Date])
85
87
  # Psych.load_file("trusted_database.yml")
86
88
  #
87
- # ==== Exception handling
89
+ # ==== \Exception handling
88
90
  #
89
91
  # begin
90
92
  # # The second argument changes only the exception contents
@@ -148,7 +150,7 @@ require_relative 'psych/class_loader'
148
150
  # # Returns Psych::Nodes::Document
149
151
  # Psych.parse_file('database.yml')
150
152
  #
151
- # ==== Exception handling
153
+ # ==== \Exception handling
152
154
  #
153
155
  # begin
154
156
  # # The second argument changes only the exception contents
@@ -340,7 +342,7 @@ module Psych
340
342
  # provided, the object contained in the first document will be returned.
341
343
  # +filename+ will be used in the exception message if any exception
342
344
  # is raised while parsing. If +yaml+ is empty, it returns
343
- # the specified +fallback+ return value, which defaults to +false+.
345
+ # the specified +fallback+ return value, which defaults to +nil+.
344
346
  #
345
347
  # Raises a Psych::SyntaxError when a YAML syntax error is detected.
346
348
  #
@@ -479,6 +481,7 @@ module Psych
479
481
  #
480
482
  # Default: <tt>2</tt>.
481
483
  # [<tt>:line_width</tt>] Max character to wrap line at.
484
+ # For unlimited line width use <tt>-1</tt>.
482
485
  #
483
486
  # Default: <tt>0</tt> (meaning "wrap at 81").
484
487
  # [<tt>:canonical</tt>] Write "canonical" YAML form (very verbose, yet
@@ -489,6 +492,10 @@ module Psych
489
492
  #
490
493
  # Default: <tt>false</tt>.
491
494
  #
495
+ # [<tt>:stringify_names</tt>] Dump symbol keys in Hash objects as string.
496
+ #
497
+ # Default: <tt>false</tt>.
498
+ #
492
499
  # Example:
493
500
  #
494
501
  # # Dump an array, get back a YAML string
@@ -502,6 +509,9 @@ module Psych
502
509
  #
503
510
  # # Dump an array to an IO with indentation set
504
511
  # Psych.dump(['a', ['b']], StringIO.new, indentation: 3)
512
+ #
513
+ # # Dump hash with symbol keys as string
514
+ # Psych.dump({a: "b"}, stringify_names: true) # => "---\na: b\n"
505
515
  def self.dump o, io = nil, options = {}
506
516
  if Hash === io
507
517
  options = io
@@ -552,6 +562,7 @@ module Psych
552
562
  #
553
563
  # Default: <tt>2</tt>.
554
564
  # [<tt>:line_width</tt>] Max character to wrap line at.
565
+ # For unlimited line width use <tt>-1</tt>.
555
566
  #
556
567
  # Default: <tt>0</tt> (meaning "wrap at 81").
557
568
  # [<tt>:canonical</tt>] Write "canonical" YAML form (very verbose, yet
@@ -562,6 +573,10 @@ module Psych
562
573
  #
563
574
  # Default: <tt>false</tt>.
564
575
  #
576
+ # [<tt>:stringify_names</tt>] Dump symbol keys in Hash objects as string.
577
+ #
578
+ # Default: <tt>false</tt>.
579
+ #
565
580
  # Example:
566
581
  #
567
582
  # # Dump an array, get back a YAML string
@@ -575,6 +590,9 @@ module Psych
575
590
  #
576
591
  # # Dump an array to an IO with indentation set
577
592
  # Psych.safe_dump(['a', ['b']], StringIO.new, indentation: 3)
593
+ #
594
+ # # Dump hash with symbol keys as string
595
+ # Psych.dump({a: "b"}, stringify_names: true) # => "---\na: b\n"
578
596
  def self.safe_dump o, io = nil, options = {}
579
597
  if Hash === io
580
598
  options = io
@@ -653,7 +671,7 @@ module Psych
653
671
  ###
654
672
  # Safely loads the document contained in +filename+. Returns the yaml contained in
655
673
  # +filename+ as a Ruby object, or if the file is empty, it returns
656
- # the specified +fallback+ return value, which defaults to +false+.
674
+ # the specified +fallback+ return value, which defaults to +nil+.
657
675
  # See safe_load for options.
658
676
  def self.safe_load_file filename, **kwargs
659
677
  File.open(filename, 'r:bom|utf-8') { |f|
@@ -664,7 +682,7 @@ module Psych
664
682
  ###
665
683
  # Loads the document contained in +filename+. Returns the yaml contained in
666
684
  # +filename+ as a Ruby object, or if the file is empty, it returns
667
- # the specified +fallback+ return value, which defaults to +false+.
685
+ # the specified +fallback+ return value, which defaults to +nil+.
668
686
  # See load for options.
669
687
  def self.load_file filename, **kwargs
670
688
  File.open(filename, 'r:bom|utf-8') { |f|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psych
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.2
4
+ version: 5.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-12-19 00:00:00.000000000 Z
13
+ date: 2025-01-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: stringio
@@ -26,6 +26,20 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: date
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
29
43
  description: |
30
44
  Psych is a YAML parser and emitter. Psych leverages libyaml[https://pyyaml.org/wiki/LibYAML]
31
45
  for its YAML parsing and emitting capabilities. In addition to wrapping libyaml,
@@ -97,6 +111,7 @@ licenses:
97
111
  - MIT
98
112
  metadata:
99
113
  msys2_mingw_dependencies: libyaml
114
+ changelog_uri: https://github.com/ruby/psych/releases
100
115
  post_install_message:
101
116
  rdoc_options:
102
117
  - "--main"
@@ -114,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
129
  - !ruby/object:Gem::Version
115
130
  version: '0'
116
131
  requirements: []
117
- rubygems_version: 3.5.1
132
+ rubygems_version: 3.5.11
118
133
  signing_key:
119
134
  specification_version: 4
120
135
  summary: Psych is a YAML parser and emitter