psych 3.1.0 → 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -0
  3. data/LICENSE +21 -0
  4. data/README.md +2 -5
  5. data/Rakefile +8 -15
  6. data/ext/psych/depend +2 -0
  7. data/ext/psych/extconf.rb +6 -2
  8. data/ext/psych/psych.c +6 -3
  9. data/ext/psych/psych_parser.c +20 -33
  10. data/ext/psych/psych_yaml_tree.c +0 -12
  11. data/ext/psych/yaml/api.c +22 -22
  12. data/ext/psych/yaml/config.h +76 -6
  13. data/ext/psych/yaml/dumper.c +1 -1
  14. data/ext/psych/yaml/emitter.c +44 -10
  15. data/ext/psych/yaml/loader.c +206 -106
  16. data/ext/psych/yaml/parser.c +6 -1
  17. data/ext/psych/yaml/scanner.c +45 -25
  18. data/ext/psych/yaml/yaml.h +43 -29
  19. data/ext/psych/yaml/yaml_private.h +4 -4
  20. data/lib/psych/class_loader.rb +10 -8
  21. data/lib/psych/core_ext.rb +1 -1
  22. data/lib/psych/exception.rb +2 -2
  23. data/lib/psych/handler.rb +1 -1
  24. data/lib/psych/handlers/document_stream.rb +1 -1
  25. data/lib/psych/handlers/recorder.rb +1 -1
  26. data/lib/psych/json/stream.rb +2 -2
  27. data/lib/psych/json/tree_builder.rb +1 -1
  28. data/lib/psych/nodes/node.rb +4 -4
  29. data/lib/psych/nodes/scalar.rb +1 -1
  30. data/lib/psych/nodes.rb +7 -7
  31. data/lib/psych/scalar_scanner.rb +25 -39
  32. data/lib/psych/syntax_error.rb +1 -1
  33. data/lib/psych/tree_builder.rb +1 -1
  34. data/lib/psych/versions.rb +3 -3
  35. data/lib/psych/visitors/json_tree.rb +1 -1
  36. data/lib/psych/visitors/to_ruby.rb +53 -20
  37. data/lib/psych/visitors/visitor.rb +17 -3
  38. data/lib/psych/visitors/yaml_tree.rb +83 -47
  39. data/lib/psych/visitors.rb +6 -6
  40. data/lib/psych.rb +222 -122
  41. data/psych.gemspec +10 -16
  42. metadata +12 -43
  43. data/.travis.yml +0 -22
  44. data/CHANGELOG.rdoc +0 -583
data/lib/psych.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/versions'
2
+ require_relative 'psych/versions'
3
3
  case RUBY_ENGINE
4
4
  when 'jruby'
5
- require 'psych_jars'
5
+ require_relative 'psych_jars'
6
6
  if JRuby::Util.respond_to?(:load_ext)
7
7
  JRuby::Util.load_ext('org.jruby.ext.psych.PsychLibrary')
8
8
  else
@@ -10,34 +10,30 @@ when 'jruby'
10
10
  org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false)
11
11
  end
12
12
  else
13
- begin
14
- require "#{RUBY_VERSION[/\d+\.\d+/]}/psych.so"
15
- rescue LoadError
16
- require 'psych.so'
17
- end
13
+ require 'psych.so'
18
14
  end
19
- require 'psych/nodes'
20
- require 'psych/streaming'
21
- require 'psych/visitors'
22
- require 'psych/handler'
23
- require 'psych/tree_builder'
24
- require 'psych/parser'
25
- require 'psych/omap'
26
- require 'psych/set'
27
- require 'psych/coder'
28
- require 'psych/core_ext'
29
- require 'psych/stream'
30
- require 'psych/json/tree_builder'
31
- require 'psych/json/stream'
32
- require 'psych/handlers/document_stream'
33
- require 'psych/class_loader'
15
+ require_relative 'psych/nodes'
16
+ require_relative 'psych/streaming'
17
+ require_relative 'psych/visitors'
18
+ require_relative 'psych/handler'
19
+ require_relative 'psych/tree_builder'
20
+ require_relative 'psych/parser'
21
+ require_relative 'psych/omap'
22
+ require_relative 'psych/set'
23
+ require_relative 'psych/coder'
24
+ require_relative 'psych/core_ext'
25
+ require_relative 'psych/stream'
26
+ require_relative 'psych/json/tree_builder'
27
+ require_relative 'psych/json/stream'
28
+ require_relative 'psych/handlers/document_stream'
29
+ require_relative 'psych/class_loader'
34
30
 
35
31
  ###
36
32
  # = Overview
37
33
  #
38
34
  # Psych is a YAML parser and emitter.
39
35
  # Psych leverages libyaml [Home page: https://pyyaml.org/wiki/LibYAML]
40
- # or [HG repo: https://bitbucket.org/xi/libyaml] for its YAML parsing
36
+ # or [git repo: https://github.com/yaml/libyaml] for its YAML parsing
41
37
  # and emitting capabilities. In addition to wrapping libyaml, Psych also
42
38
  # knows how to serialize and de-serialize most Ruby objects to and from
43
39
  # the YAML format.
@@ -78,12 +74,15 @@ require 'psych/class_loader'
78
74
  #
79
75
  # ==== Reading from a string
80
76
  #
81
- # Psych.load("--- a") # => 'a'
82
- # Psych.load("---\n - a\n - b") # => ['a', 'b']
77
+ # Psych.safe_load("--- a") # => 'a'
78
+ # Psych.safe_load("---\n - a\n - b") # => ['a', 'b']
79
+ # # From a trusted string:
80
+ # Psych.load("--- !ruby/range\nbegin: 0\nend: 42\nexcl: false\n") # => 0..42
83
81
  #
84
82
  # ==== Reading from a file
85
83
  #
86
- # Psych.load_file("database.yml")
84
+ # Psych.safe_load_file("data.yml", permitted_classes: [Date])
85
+ # Psych.load_file("trusted_database.yml")
87
86
  #
88
87
  # ==== Exception handling
89
88
  #
@@ -234,10 +233,7 @@ require 'psych/class_loader'
234
233
 
235
234
  module Psych
236
235
  # The version of libyaml Psych is using
237
- LIBYAML_VERSION = Psych.libyaml_version.join '.'
238
- # Deprecation guard
239
- NOT_GIVEN = Object.new
240
- private_constant :NOT_GIVEN
236
+ LIBYAML_VERSION = Psych.libyaml_version.join('.').freeze
241
237
 
242
238
  ###
243
239
  # Load +yaml+ in to a Ruby data structure. If multiple documents are
@@ -250,11 +246,11 @@ module Psych
250
246
  #
251
247
  # Example:
252
248
  #
253
- # Psych.load("--- a") # => 'a'
254
- # Psych.load("---\n - a\n - b") # => ['a', 'b']
249
+ # Psych.unsafe_load("--- a") # => 'a'
250
+ # Psych.unsafe_load("---\n - a\n - b") # => ['a', 'b']
255
251
  #
256
252
  # begin
257
- # Psych.load("--- `", filename: "file.txt")
253
+ # Psych.unsafe_load("--- `", filename: "file.txt")
258
254
  # rescue Psych::SyntaxError => ex
259
255
  # ex.file # => 'file.txt'
260
256
  # ex.message # => "(file.txt): found character that cannot start any token"
@@ -263,23 +259,21 @@ module Psych
263
259
  # When the optional +symbolize_names+ keyword argument is set to a
264
260
  # true value, returns symbols for keys in Hash objects (default: strings).
265
261
  #
266
- # Psych.load("---\n foo: bar") # => {"foo"=>"bar"}
267
- # Psych.load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
262
+ # Psych.unsafe_load("---\n foo: bar") # => {"foo"=>"bar"}
263
+ # Psych.unsafe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
268
264
  #
269
265
  # Raises a TypeError when `yaml` parameter is NilClass
270
266
  #
271
- def self.load yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: false, symbolize_names: false
272
- if legacy_filename != NOT_GIVEN
273
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.load is deprecated. Use keyword argument like Psych.load(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
274
- filename = legacy_filename
275
- end
276
-
267
+ # NOTE: This method *should not* be used to parse untrusted documents, such as
268
+ # YAML documents that are supplied via user input. Instead, please use the
269
+ # load method or the safe_load method.
270
+ #
271
+ def self.unsafe_load yaml, filename: nil, fallback: false, symbolize_names: false, freeze: false
277
272
  result = parse(yaml, filename: filename)
278
273
  return fallback unless result
279
- result = result.to_ruby if result
280
- symbolize_names!(result) if symbolize_names
281
- result
274
+ result.to_ruby(symbolize_names: symbolize_names, freeze: freeze)
282
275
  end
276
+ class << self; alias :load :unsafe_load; end
283
277
 
284
278
  ###
285
279
  # Safely load the yaml string in +yaml+. By default, only the following
@@ -288,7 +282,8 @@ module Psych
288
282
  # * TrueClass
289
283
  # * FalseClass
290
284
  # * NilClass
291
- # * Numeric
285
+ # * Integer
286
+ # * Float
292
287
  # * String
293
288
  # * Array
294
289
  # * Hash
@@ -325,27 +320,7 @@ module Psych
325
320
  # Psych.safe_load("---\n foo: bar") # => {"foo"=>"bar"}
326
321
  # Psych.safe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
327
322
  #
328
- def self.safe_load yaml, legacy_permitted_classes = NOT_GIVEN, legacy_permitted_symbols = NOT_GIVEN, legacy_aliases = NOT_GIVEN, legacy_filename = NOT_GIVEN, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false
329
- if legacy_permitted_classes != NOT_GIVEN
330
- warn_with_uplevel 'Passing permitted_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_classes: ...) instead.', uplevel: 1 if $VERBOSE
331
- permitted_classes = legacy_permitted_classes
332
- end
333
-
334
- if legacy_permitted_symbols != NOT_GIVEN
335
- warn_with_uplevel 'Passing permitted_symbols with the 3rd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_symbols: ...) instead.', uplevel: 1 if $VERBOSE
336
- permitted_symbols = legacy_permitted_symbols
337
- end
338
-
339
- if legacy_aliases != NOT_GIVEN
340
- warn_with_uplevel 'Passing aliases with the 4th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, aliases: ...) instead.', uplevel: 1 if $VERBOSE
341
- aliases = legacy_aliases
342
- end
343
-
344
- if legacy_filename != NOT_GIVEN
345
- warn_with_uplevel 'Passing filename with the 5th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
346
- filename = legacy_filename
347
- end
348
-
323
+ def self.safe_load yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
349
324
  result = parse(yaml, filename: filename)
350
325
  return fallback unless result
351
326
 
@@ -353,15 +328,54 @@ module Psych
353
328
  permitted_symbols.map(&:to_s))
354
329
  scanner = ScalarScanner.new class_loader
355
330
  visitor = if aliases
356
- Visitors::ToRuby.new scanner, class_loader
331
+ Visitors::ToRuby.new scanner, class_loader, symbolize_names: symbolize_names, freeze: freeze
357
332
  else
358
- Visitors::NoAliasRuby.new scanner, class_loader
333
+ Visitors::NoAliasRuby.new scanner, class_loader, symbolize_names: symbolize_names, freeze: freeze
359
334
  end
360
335
  result = visitor.accept result
361
- symbolize_names!(result) if symbolize_names
362
336
  result
363
337
  end
364
338
 
339
+ ###
340
+ # Load +yaml+ in to a Ruby data structure. If multiple documents are
341
+ # provided, the object contained in the first document will be returned.
342
+ # +filename+ will be used in the exception message if any exception
343
+ # is raised while parsing. If +yaml+ is empty, it returns
344
+ # the specified +fallback+ return value, which defaults to +false+.
345
+ #
346
+ # Raises a Psych::SyntaxError when a YAML syntax error is detected.
347
+ #
348
+ # Example:
349
+ #
350
+ # Psych.load("--- a") # => 'a'
351
+ # Psych.load("---\n - a\n - b") # => ['a', 'b']
352
+ #
353
+ # begin
354
+ # Psych.load("--- `", filename: "file.txt")
355
+ # rescue Psych::SyntaxError => ex
356
+ # ex.file # => 'file.txt'
357
+ # ex.message # => "(file.txt): found character that cannot start any token"
358
+ # end
359
+ #
360
+ # When the optional +symbolize_names+ keyword argument is set to a
361
+ # true value, returns symbols for keys in Hash objects (default: strings).
362
+ #
363
+ # Psych.load("---\n foo: bar") # => {"foo"=>"bar"}
364
+ # Psych.load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
365
+ #
366
+ # Raises a TypeError when `yaml` parameter is NilClass. This method is
367
+ # similar to `safe_load` except that `Symbol` objects are allowed by default.
368
+ #
369
+ def self.load yaml, permitted_classes: [Symbol], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
370
+ safe_load yaml, permitted_classes: permitted_classes,
371
+ permitted_symbols: permitted_symbols,
372
+ aliases: aliases,
373
+ filename: filename,
374
+ fallback: fallback,
375
+ symbolize_names: symbolize_names,
376
+ freeze: freeze
377
+ end
378
+
365
379
  ###
366
380
  # Parse a YAML string in +yaml+. Returns the Psych::Nodes::Document.
367
381
  # +filename+ is used in the exception message if a Psych::SyntaxError is
@@ -381,22 +395,12 @@ module Psych
381
395
  # end
382
396
  #
383
397
  # See Psych::Nodes for more information about YAML AST.
384
- def self.parse yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: NOT_GIVEN
385
- if legacy_filename != NOT_GIVEN
386
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.parse is deprecated. Use keyword argument like Psych.parse(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
387
- filename = legacy_filename
388
- end
389
-
398
+ def self.parse yaml, filename: nil
390
399
  parse_stream(yaml, filename: filename) do |node|
391
400
  return node
392
401
  end
393
402
 
394
- if fallback != NOT_GIVEN
395
- warn_with_uplevel 'Passing the `fallback` keyword argument of Psych.parse is deprecated.', uplevel: 1 if $VERBOSE
396
- fallback
397
- else
398
- false
399
- end
403
+ false
400
404
  end
401
405
 
402
406
  ###
@@ -445,12 +449,7 @@ module Psych
445
449
  # Raises a TypeError when NilClass is passed.
446
450
  #
447
451
  # See Psych::Nodes for more information about YAML AST.
448
- def self.parse_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, &block
449
- if legacy_filename != NOT_GIVEN
450
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.parse_stream is deprecated. Use keyword argument like Psych.parse_stream(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
451
- filename = legacy_filename
452
- end
453
-
452
+ def self.parse_stream yaml, filename: nil, &block
454
453
  if block_given?
455
454
  parser = Psych::Parser.new(Handlers::DocumentStream.new(&block))
456
455
  parser.parse yaml, filename
@@ -514,6 +513,79 @@ module Psych
514
513
  visitor.tree.yaml io, options
515
514
  end
516
515
 
516
+ ###
517
+ # call-seq:
518
+ # Psych.safe_dump(o) -> string of yaml
519
+ # Psych.safe_dump(o, options) -> string of yaml
520
+ # Psych.safe_dump(o, io) -> io object passed in
521
+ # Psych.safe_dump(o, io, options) -> io object passed in
522
+ #
523
+ # Safely dump Ruby object +o+ to a YAML string. Optional +options+ may be passed in
524
+ # to control the output format. If an IO object is passed in, the YAML will
525
+ # be dumped to that IO object. By default, only the following
526
+ # classes are allowed to be serialized:
527
+ #
528
+ # * TrueClass
529
+ # * FalseClass
530
+ # * NilClass
531
+ # * Integer
532
+ # * Float
533
+ # * String
534
+ # * Array
535
+ # * Hash
536
+ #
537
+ # Arbitrary classes can be allowed by adding those classes to the +permitted_classes+
538
+ # keyword argument. They are additive. For example, to allow Date serialization:
539
+ #
540
+ # Psych.safe_dump(yaml, permitted_classes: [Date])
541
+ #
542
+ # Now the Date class can be dumped in addition to the classes listed above.
543
+ #
544
+ # A Psych::DisallowedClass exception will be raised if the object contains a
545
+ # class that isn't in the +permitted_classes+ list.
546
+ #
547
+ # Currently supported options are:
548
+ #
549
+ # [<tt>:indentation</tt>] Number of space characters used to indent.
550
+ # Acceptable value should be in <tt>0..9</tt> range,
551
+ # otherwise option is ignored.
552
+ #
553
+ # Default: <tt>2</tt>.
554
+ # [<tt>:line_width</tt>] Max character to wrap line at.
555
+ #
556
+ # Default: <tt>0</tt> (meaning "wrap at 81").
557
+ # [<tt>:canonical</tt>] Write "canonical" YAML form (very verbose, yet
558
+ # strictly formal).
559
+ #
560
+ # Default: <tt>false</tt>.
561
+ # [<tt>:header</tt>] Write <tt>%YAML [version]</tt> at the beginning of document.
562
+ #
563
+ # Default: <tt>false</tt>.
564
+ #
565
+ # Example:
566
+ #
567
+ # # Dump an array, get back a YAML string
568
+ # Psych.safe_dump(['a', 'b']) # => "---\n- a\n- b\n"
569
+ #
570
+ # # Dump an array to an IO object
571
+ # Psych.safe_dump(['a', 'b'], StringIO.new) # => #<StringIO:0x000001009d0890>
572
+ #
573
+ # # Dump an array with indentation set
574
+ # Psych.safe_dump(['a', ['b']], indentation: 3) # => "---\n- a\n- - b\n"
575
+ #
576
+ # # Dump an array to an IO with indentation set
577
+ # Psych.safe_dump(['a', ['b']], StringIO.new, indentation: 3)
578
+ def self.safe_dump o, io = nil, options = {}
579
+ if Hash === io
580
+ options = io
581
+ io = nil
582
+ end
583
+
584
+ visitor = Psych::Visitors::RestrictedYAMLTree.create options
585
+ visitor << o
586
+ visitor.tree.yaml io, options
587
+ end
588
+
517
589
  ###
518
590
  # Dump a list of objects as separate documents to a document stream.
519
591
  #
@@ -551,18 +623,13 @@ module Psych
551
623
  # end
552
624
  # list # => ['foo', 'bar']
553
625
  #
554
- def self.load_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: []
555
- if legacy_filename != NOT_GIVEN
556
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.load_stream is deprecated. Use keyword argument like Psych.load_stream(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
557
- filename = legacy_filename
558
- end
559
-
626
+ def self.load_stream yaml, filename: nil, fallback: [], **kwargs
560
627
  result = if block_given?
561
628
  parse_stream(yaml, filename: filename) do |node|
562
- yield node.to_ruby
629
+ yield node.to_ruby(**kwargs)
563
630
  end
564
631
  else
565
- parse_stream(yaml, filename: filename).children.map(&:to_ruby)
632
+ parse_stream(yaml, filename: filename).children.map { |node| node.to_ruby(**kwargs) }
566
633
  end
567
634
 
568
635
  return fallback if result.is_a?(Array) && result.empty?
@@ -573,49 +640,59 @@ module Psych
573
640
  # Load the document contained in +filename+. Returns the yaml contained in
574
641
  # +filename+ as a Ruby object, or if the file is empty, it returns
575
642
  # the specified +fallback+ return value, which defaults to +false+.
576
- def self.load_file filename, fallback: false
643
+ #
644
+ # NOTE: This method *should not* be used to parse untrusted documents, such as
645
+ # YAML documents that are supplied via user input. Instead, please use the
646
+ # safe_load_file method.
647
+ def self.unsafe_load_file filename, **kwargs
577
648
  File.open(filename, 'r:bom|utf-8') { |f|
578
- self.load f, filename: filename, fallback: fallback
649
+ self.unsafe_load f, filename: filename, **kwargs
650
+ }
651
+ end
652
+
653
+ ###
654
+ # Safely loads the document contained in +filename+. Returns the yaml contained in
655
+ # +filename+ as a Ruby object, or if the file is empty, it returns
656
+ # the specified +fallback+ return value, which defaults to +false+.
657
+ # See safe_load for options.
658
+ def self.safe_load_file filename, **kwargs
659
+ File.open(filename, 'r:bom|utf-8') { |f|
660
+ self.safe_load f, filename: filename, **kwargs
661
+ }
662
+ end
663
+
664
+ ###
665
+ # Loads the document contained in +filename+. Returns the yaml contained in
666
+ # +filename+ as a Ruby object, or if the file is empty, it returns
667
+ # the specified +fallback+ return value, which defaults to +false+.
668
+ # See load for options.
669
+ def self.load_file filename, **kwargs
670
+ File.open(filename, 'r:bom|utf-8') { |f|
671
+ self.load f, filename: filename, **kwargs
579
672
  }
580
673
  end
581
674
 
582
675
  # :stopdoc:
583
- @domain_types = {}
584
676
  def self.add_domain_type domain, type_tag, &block
585
677
  key = ['tag', domain, type_tag].join ':'
586
- @domain_types[key] = [key, block]
587
- @domain_types["tag:#{type_tag}"] = [key, block]
678
+ domain_types[key] = [key, block]
679
+ domain_types["tag:#{type_tag}"] = [key, block]
588
680
  end
589
681
 
590
682
  def self.add_builtin_type type_tag, &block
591
683
  domain = 'yaml.org,2002'
592
684
  key = ['tag', domain, type_tag].join ':'
593
- @domain_types[key] = [key, block]
685
+ domain_types[key] = [key, block]
594
686
  end
595
687
 
596
688
  def self.remove_type type_tag
597
- @domain_types.delete type_tag
689
+ domain_types.delete type_tag
598
690
  end
599
691
 
600
- @load_tags = {}
601
- @dump_tags = {}
602
692
  def self.add_tag tag, klass
603
- @load_tags[tag] = klass.name
604
- @dump_tags[klass] = tag
605
- end
606
-
607
- def self.symbolize_names!(result)
608
- case result
609
- when Hash
610
- result.keys.each do |key|
611
- result[key.to_sym] = symbolize_names!(result.delete(key))
612
- end
613
- when Array
614
- result.map! { |r| symbolize_names!(r) }
615
- end
616
- result
693
+ load_tags[tag] = klass.name
694
+ dump_tags[klass] = tag
617
695
  end
618
- private_class_method :symbolize_names!
619
696
 
620
697
  # Workaround for emulating `warn '...', uplevel: 1` in Ruby 2.4 or lower.
621
698
  def self.warn_with_uplevel(message, uplevel: 1)
@@ -633,9 +710,32 @@ module Psych
633
710
  private_class_method :warn_with_uplevel, :parse_caller
634
711
 
635
712
  class << self
636
- attr_accessor :load_tags
637
- attr_accessor :dump_tags
638
- attr_accessor :domain_types
713
+ if defined?(Ractor)
714
+ require 'forwardable'
715
+ extend Forwardable
716
+
717
+ class Config
718
+ attr_accessor :load_tags, :dump_tags, :domain_types
719
+ def initialize
720
+ @load_tags = {}
721
+ @dump_tags = {}
722
+ @domain_types = {}
723
+ end
724
+ end
725
+
726
+ def config
727
+ Ractor.current[:PsychConfig] ||= Config.new
728
+ end
729
+
730
+ def_delegators :config, :load_tags, :dump_tags, :domain_types, :load_tags=, :dump_tags=, :domain_types=
731
+ else
732
+ attr_accessor :load_tags
733
+ attr_accessor :dump_tags
734
+ attr_accessor :domain_types
735
+ end
639
736
  end
737
+ self.load_tags = {}
738
+ self.dump_tags = {}
739
+ self.domain_types = {}
640
740
  # :startdoc:
641
741
  end
data/psych.gemspec CHANGED
@@ -1,16 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require_relative 'lib/psych/versions'
6
- rescue LoadError
7
- # for Ruby core repository
8
- require_relative 'versions'
4
+ version_module = Module.new do
5
+ version_rb = File.join(__dir__, "lib/psych/versions.rb")
6
+ module_eval(File.read(version_rb), version_rb)
9
7
  end
10
8
 
11
9
  Gem::Specification.new do |s|
12
10
  s.name = "psych"
13
- s.version = Psych::VERSION
11
+ s.version = version_module::Psych::VERSION
14
12
  s.authors = ["Aaron Patterson", "SHIBATA Hiroshi", "Charles Oliver Nutter"]
15
13
  s.email = ["aaron@tenderlovemaking.com", "hsbt@ruby-lang.org", "headius@headius.com"]
16
14
  s.summary = "Psych is a YAML parser and emitter"
@@ -25,7 +23,7 @@ DESCRIPTION
25
23
 
26
24
  # for ruby core repository. It was generated by `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
25
  s.files = [
28
- ".gitignore", ".travis.yml", "CHANGELOG.rdoc", "Gemfile", "Mavenfile", "README.md", "Rakefile", "bin/console",
26
+ ".gitignore", "Gemfile", "LICENSE", "Mavenfile", "README.md", "Rakefile", "bin/console",
29
27
  "bin/setup", "ext/psych/depend", "ext/psych/extconf.rb", "ext/psych/psych.c", "ext/psych/psych.h",
30
28
  "ext/psych/psych_emitter.c", "ext/psych/psych_emitter.h", "ext/psych/psych_parser.c", "ext/psych/psych_parser.h",
31
29
  "ext/psych/psych_to_ruby.c", "ext/psych/psych_to_ruby.h", "ext/psych/psych_yaml_tree.c", "ext/psych/psych_yaml_tree.h",
@@ -45,15 +43,11 @@ DESCRIPTION
45
43
  ]
46
44
 
47
45
  s.rdoc_options = ["--main", "README.md"]
48
- s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md"]
46
+ s.extra_rdoc_files = ["README.md"]
49
47
 
50
- s.required_ruby_version = Gem::Requirement.new(">= 2.2.2")
51
- s.rubygems_version = "2.5.1"
48
+ s.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
52
49
  s.required_rubygems_version = Gem::Requirement.new(">= 0")
53
50
 
54
- s.add_development_dependency 'rake-compiler', ">= 0.4.1"
55
- s.add_development_dependency 'minitest', "~> 5.0"
56
-
57
51
  if RUBY_ENGINE == 'jruby'
58
52
  s.platform = 'java'
59
53
  s.files.concat [
@@ -65,11 +59,11 @@ DESCRIPTION
65
59
  "lib/psych_jars.rb",
66
60
  "lib/psych.jar"
67
61
  ]
68
- s.requirements = "jar org.yaml:snakeyaml, #{Psych::DEFAULT_SNAKEYAML_VERSION}"
62
+ s.requirements = "jar org.yaml:snakeyaml, #{version_module::Psych::DEFAULT_SNAKEYAML_VERSION}"
69
63
  s.add_dependency 'jar-dependencies', '>= 0.1.7'
70
- s.add_development_dependency 'ruby-maven'
71
64
  else
72
65
  s.extensions = ["ext/psych/extconf.rb"]
73
- s.add_development_dependency 'rake-compiler-dock', ">= 0.6.3"
66
+ s.add_dependency 'stringio'
74
67
  end
68
+
75
69
  end
metadata CHANGED
@@ -1,59 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psych
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
8
  - SHIBATA Hiroshi
9
9
  - Charles Oliver Nutter
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-12-18 00:00:00.000000000 Z
13
+ date: 2021-12-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rake-compiler
16
+ name: stringio
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 0.4.1
22
- type: :development
21
+ version: '0'
22
+ type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 0.4.1
29
- - !ruby/object:Gem::Dependency
30
- name: minitest
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - "~>"
34
- - !ruby/object:Gem::Version
35
- version: '5.0'
36
- type: :development
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '5.0'
43
- - !ruby/object:Gem::Dependency
44
- name: rake-compiler-dock
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 0.6.3
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 0.6.3
28
+ version: '0'
57
29
  description: |
58
30
  Psych is a YAML parser and emitter. Psych leverages libyaml[https://pyyaml.org/wiki/LibYAML]
59
31
  for its YAML parsing and emitting capabilities. In addition to wrapping libyaml,
@@ -66,13 +38,11 @@ executables: []
66
38
  extensions:
67
39
  - ext/psych/extconf.rb
68
40
  extra_rdoc_files:
69
- - CHANGELOG.rdoc
70
41
  - README.md
71
42
  files:
72
43
  - ".gitignore"
73
- - ".travis.yml"
74
- - CHANGELOG.rdoc
75
44
  - Gemfile
45
+ - LICENSE
76
46
  - Mavenfile
77
47
  - README.md
78
48
  - Rakefile
@@ -144,7 +114,7 @@ homepage: https://github.com/ruby/psych
144
114
  licenses:
145
115
  - MIT
146
116
  metadata: {}
147
- post_install_message:
117
+ post_install_message:
148
118
  rdoc_options:
149
119
  - "--main"
150
120
  - README.md
@@ -154,16 +124,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
124
  requirements:
155
125
  - - ">="
156
126
  - !ruby/object:Gem::Version
157
- version: 2.2.2
127
+ version: 2.4.0
158
128
  required_rubygems_version: !ruby/object:Gem::Requirement
159
129
  requirements:
160
130
  - - ">="
161
131
  - !ruby/object:Gem::Version
162
132
  version: '0'
163
133
  requirements: []
164
- rubyforge_project:
165
- rubygems_version: 2.7.6
166
- signing_key:
134
+ rubygems_version: 3.3.0.dev
135
+ signing_key:
167
136
  specification_version: 4
168
137
  summary: Psych is a YAML parser and emitter
169
138
  test_files: []