cybrid_api_id_ruby 0.8.12 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/README.md +5 -5
  4. data/cybrid_api_id_ruby.gemspec +1 -1
  5. data/lib/cybrid_api_id_ruby/api/bank_applications_idp_api.rb +1 -1
  6. data/lib/cybrid_api_id_ruby/api/organization_applications_idp_api.rb +1 -1
  7. data/lib/cybrid_api_id_ruby/api_client.rb +1 -1
  8. data/lib/cybrid_api_id_ruby/api_error.rb +1 -1
  9. data/lib/cybrid_api_id_ruby/configuration.rb +1 -1
  10. data/lib/cybrid_api_id_ruby/models/application_idp_model.rb +1 -1
  11. data/lib/cybrid_api_id_ruby/models/application_list_idp_model.rb +1 -1
  12. data/lib/cybrid_api_id_ruby/models/application_with_secret_all_of_idp_model.rb +1 -1
  13. data/lib/cybrid_api_id_ruby/models/application_with_secret_idp_model.rb +1 -1
  14. data/lib/cybrid_api_id_ruby/models/post_bank_application_idp_model.rb +1 -1
  15. data/lib/cybrid_api_id_ruby/models/post_organization_application_idp_model.rb +1 -1
  16. data/lib/cybrid_api_id_ruby/version.rb +2 -2
  17. data/lib/cybrid_api_id_ruby.rb +1 -1
  18. data/spec/api/bank_applications_idp_api_spec.rb +1 -1
  19. data/spec/api/organization_applications_idp_api_spec.rb +1 -1
  20. data/spec/api_client_spec.rb +1 -1
  21. data/spec/configuration_spec.rb +1 -1
  22. data/spec/models/application_idp_model_spec.rb +1 -1
  23. data/spec/models/application_list_idp_model_spec.rb +1 -1
  24. data/spec/models/application_with_secret_all_of_idp_model_spec.rb +1 -1
  25. data/spec/models/application_with_secret_idp_model_spec.rb +1 -1
  26. data/spec/models/post_bank_application_idp_model_spec.rb +1 -1
  27. data/spec/models/post_organization_application_idp_model_spec.rb +1 -1
  28. data/spec/spec_helper.rb +1 -1
  29. data/vendor/bundle/ruby/3.1.0/cache/psych-4.0.4.gem +0 -0
  30. data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/byebug-11.1.3/gem_make.out +2 -2
  31. data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/ffi-1.15.5/gem_make.out +2 -2
  32. data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/jaro_winkler-1.5.4/gem_make.out +2 -2
  33. data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/psych-4.0.4/gem.build_complete +0 -0
  34. data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/psych-4.0.4/gem_make.out +27 -0
  35. data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/psych-4.0.4/mkmf.log +75 -0
  36. data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/psych-4.0.4/psych.so +0 -0
  37. data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/stringio-3.0.2/gem_make.out +2 -2
  38. data/vendor/bundle/ruby/3.1.0/gems/byebug-11.1.3/ext/byebug/Makefile +2 -2
  39. data/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/ext/ffi_c/Makefile +2 -2
  40. data/vendor/bundle/ruby/3.1.0/gems/jaro_winkler-1.5.4/ext/jaro_winkler/Makefile +2 -2
  41. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/.gitignore +16 -0
  42. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/Gemfile +9 -0
  43. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/LICENSE +21 -0
  44. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/Mavenfile +7 -0
  45. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/README.md +72 -0
  46. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/Rakefile +41 -0
  47. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/bin/console +7 -0
  48. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/bin/setup +6 -0
  49. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/.sitearchdir.time +0 -0
  50. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/Makefile +274 -0
  51. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/depend +5 -0
  52. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/extconf.rb +43 -0
  53. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych.c +37 -0
  54. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych.h +17 -0
  55. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych.o +0 -0
  56. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych.so +0 -0
  57. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_emitter.c +555 -0
  58. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_emitter.h +8 -0
  59. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_emitter.o +0 -0
  60. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_parser.c +579 -0
  61. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_parser.h +6 -0
  62. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_parser.o +0 -0
  63. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_to_ruby.c +39 -0
  64. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_to_ruby.h +8 -0
  65. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_to_ruby.o +0 -0
  66. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_yaml_tree.c +12 -0
  67. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_yaml_tree.h +8 -0
  68. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_yaml_tree.o +0 -0
  69. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/LICENSE +19 -0
  70. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/api.c +1393 -0
  71. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/config.h +80 -0
  72. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/dumper.c +394 -0
  73. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/emitter.c +2358 -0
  74. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/loader.c +544 -0
  75. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/parser.c +1375 -0
  76. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/reader.c +469 -0
  77. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/scanner.c +3598 -0
  78. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/writer.c +141 -0
  79. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/yaml.h +1985 -0
  80. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/yaml_private.h +688 -0
  81. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/class_loader.rb +104 -0
  82. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/coder.rb +95 -0
  83. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/core_ext.rb +19 -0
  84. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/exception.rb +14 -0
  85. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/handler.rb +255 -0
  86. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/handlers/document_stream.rb +23 -0
  87. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/handlers/recorder.rb +40 -0
  88. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/json/ruby_events.rb +20 -0
  89. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/json/stream.rb +17 -0
  90. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/json/tree_builder.rb +13 -0
  91. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/json/yaml_events.rb +30 -0
  92. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/alias.rb +21 -0
  93. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/document.rb +63 -0
  94. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/mapping.rb +59 -0
  95. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/node.rb +75 -0
  96. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/scalar.rb +70 -0
  97. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/sequence.rb +84 -0
  98. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/stream.rb +40 -0
  99. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes.rb +78 -0
  100. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/omap.rb +5 -0
  101. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/parser.rb +52 -0
  102. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/scalar_scanner.rb +142 -0
  103. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/set.rb +5 -0
  104. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/stream.rb +38 -0
  105. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/streaming.rb +28 -0
  106. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/syntax_error.rb +22 -0
  107. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/tree_builder.rb +137 -0
  108. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/versions.rb +10 -0
  109. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/depth_first.rb +27 -0
  110. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/emitter.rb +52 -0
  111. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/json_tree.rb +25 -0
  112. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb +434 -0
  113. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/visitor.rb +34 -0
  114. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/yaml_tree.rb +587 -0
  115. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors.rb +7 -0
  116. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/y.rb +10 -0
  117. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych.rb +741 -0
  118. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych.so +0 -0
  119. data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/psych.gemspec +69 -0
  120. data/vendor/bundle/ruby/3.1.0/gems/stringio-3.0.2/ext/stringio/Makefile +2 -2
  121. data/vendor/bundle/ruby/3.1.0/specifications/psych-4.0.4.gemspec +36 -0
  122. metadata +87 -2
@@ -0,0 +1,434 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../scalar_scanner'
3
+ require_relative '../class_loader'
4
+ require_relative '../exception'
5
+
6
+ unless defined?(Regexp::NOENCODING)
7
+ Regexp::NOENCODING = 32
8
+ end
9
+
10
+ module Psych
11
+ module Visitors
12
+ ###
13
+ # This class walks a YAML AST, converting each node to Ruby
14
+ class ToRuby < Psych::Visitors::Visitor
15
+ def self.create(symbolize_names: false, freeze: false, strict_integer: false)
16
+ class_loader = ClassLoader.new
17
+ scanner = ScalarScanner.new class_loader, strict_integer: strict_integer
18
+ new(scanner, class_loader, symbolize_names: symbolize_names, freeze: freeze)
19
+ end
20
+
21
+ attr_reader :class_loader
22
+
23
+ def initialize ss, class_loader, symbolize_names: false, freeze: false
24
+ super()
25
+ @st = {}
26
+ @ss = ss
27
+ @load_tags = Psych.load_tags
28
+ @domain_types = Psych.domain_types
29
+ @class_loader = class_loader
30
+ @symbolize_names = symbolize_names
31
+ @freeze = freeze
32
+ end
33
+
34
+ def accept target
35
+ result = super
36
+
37
+ unless @domain_types.empty? || !target.tag
38
+ key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:')
39
+ key = "tag:#{key}" unless key =~ /^(?:tag:|x-private)/
40
+
41
+ if @domain_types.key? key
42
+ value, block = @domain_types[key]
43
+ result = block.call value, result
44
+ end
45
+ end
46
+
47
+ result = deduplicate(result).freeze if @freeze
48
+ result
49
+ end
50
+
51
+ def deserialize o
52
+ if klass = resolve_class(@load_tags[o.tag])
53
+ instance = klass.allocate
54
+
55
+ if instance.respond_to?(:init_with)
56
+ coder = Psych::Coder.new(o.tag)
57
+ coder.scalar = o.value
58
+ instance.init_with coder
59
+ end
60
+
61
+ return instance
62
+ end
63
+
64
+ return o.value if o.quoted
65
+ return @ss.tokenize(o.value) unless o.tag
66
+
67
+ case o.tag
68
+ when '!binary', 'tag:yaml.org,2002:binary'
69
+ o.value.unpack('m').first
70
+ when /^!(?:str|ruby\/string)(?::(.*))?$/, 'tag:yaml.org,2002:str'
71
+ klass = resolve_class($1)
72
+ if klass
73
+ klass.allocate.replace o.value
74
+ else
75
+ o.value
76
+ end
77
+ when '!ruby/object:BigDecimal'
78
+ require 'bigdecimal' unless defined? BigDecimal
79
+ class_loader.big_decimal._load o.value
80
+ when "!ruby/object:DateTime"
81
+ class_loader.date_time
82
+ require 'date' unless defined? DateTime
83
+ @ss.parse_time(o.value).to_datetime
84
+ when '!ruby/encoding'
85
+ ::Encoding.find o.value
86
+ when "!ruby/object:Complex"
87
+ class_loader.complex
88
+ Complex(o.value)
89
+ when "!ruby/object:Rational"
90
+ class_loader.rational
91
+ Rational(o.value)
92
+ when "!ruby/class", "!ruby/module"
93
+ resolve_class o.value
94
+ when "tag:yaml.org,2002:float", "!float"
95
+ Float(@ss.tokenize(o.value))
96
+ when "!ruby/regexp"
97
+ klass = class_loader.regexp
98
+ o.value =~ /^\/(.*)\/([mixn]*)$/m
99
+ source = $1
100
+ options = 0
101
+ lang = nil
102
+ ($2 || '').split('').each do |option|
103
+ case option
104
+ when 'x' then options |= Regexp::EXTENDED
105
+ when 'i' then options |= Regexp::IGNORECASE
106
+ when 'm' then options |= Regexp::MULTILINE
107
+ when 'n' then options |= Regexp::NOENCODING
108
+ else lang = option
109
+ end
110
+ end
111
+ klass.new(*[source, options, lang].compact)
112
+ when "!ruby/range"
113
+ klass = class_loader.range
114
+ args = o.value.split(/([.]{2,3})/, 2).map { |s|
115
+ accept Nodes::Scalar.new(s)
116
+ }
117
+ args.push(args.delete_at(1) == '...')
118
+ klass.new(*args)
119
+ when /^!ruby\/sym(bol)?:?(.*)?$/
120
+ class_loader.symbolize o.value
121
+ else
122
+ @ss.tokenize o.value
123
+ end
124
+ end
125
+ private :deserialize
126
+
127
+ def visit_Psych_Nodes_Scalar o
128
+ register o, deserialize(o)
129
+ end
130
+
131
+ def visit_Psych_Nodes_Sequence o
132
+ if klass = resolve_class(@load_tags[o.tag])
133
+ instance = klass.allocate
134
+
135
+ if instance.respond_to?(:init_with)
136
+ coder = Psych::Coder.new(o.tag)
137
+ coder.seq = o.children.map { |c| accept c }
138
+ instance.init_with coder
139
+ end
140
+
141
+ return instance
142
+ end
143
+
144
+ case o.tag
145
+ when nil
146
+ register_empty(o)
147
+ when '!omap', 'tag:yaml.org,2002:omap'
148
+ map = register(o, Psych::Omap.new)
149
+ o.children.each { |a|
150
+ map[accept(a.children.first)] = accept a.children.last
151
+ }
152
+ map
153
+ when /^!(?:seq|ruby\/array):(.*)$/
154
+ klass = resolve_class($1)
155
+ list = register(o, klass.allocate)
156
+ o.children.each { |c| list.push accept c }
157
+ list
158
+ else
159
+ register_empty(o)
160
+ end
161
+ end
162
+
163
+ def visit_Psych_Nodes_Mapping o
164
+ if @load_tags[o.tag]
165
+ return revive(resolve_class(@load_tags[o.tag]), o)
166
+ end
167
+ return revive_hash(register(o, {}), o) unless o.tag
168
+
169
+ case o.tag
170
+ when /^!ruby\/struct:?(.*)?$/
171
+ klass = resolve_class($1) if $1
172
+
173
+ if klass
174
+ s = register(o, klass.allocate)
175
+
176
+ members = {}
177
+ struct_members = s.members.map { |x| class_loader.symbolize x }
178
+ o.children.each_slice(2) do |k,v|
179
+ member = accept(k)
180
+ value = accept(v)
181
+ if struct_members.include?(class_loader.symbolize(member))
182
+ s.send("#{member}=", value)
183
+ else
184
+ members[member.to_s.sub(/^@/, '')] = value
185
+ end
186
+ end
187
+ init_with(s, members, o)
188
+ else
189
+ klass = class_loader.struct
190
+ members = o.children.map { |c| accept c }
191
+ h = Hash[*members]
192
+ s = klass.new(*h.map { |k,v|
193
+ class_loader.symbolize k
194
+ }).new(*h.map { |k,v| v })
195
+ register(o, s)
196
+ s
197
+ end
198
+
199
+ when /^!ruby\/object:?(.*)?$/
200
+ name = $1 || 'Object'
201
+
202
+ if name == 'Complex'
203
+ class_loader.complex
204
+ h = Hash[*o.children.map { |c| accept c }]
205
+ register o, Complex(h['real'], h['image'])
206
+ elsif name == 'Rational'
207
+ class_loader.rational
208
+ h = Hash[*o.children.map { |c| accept c }]
209
+ register o, Rational(h['numerator'], h['denominator'])
210
+ elsif name == 'Hash'
211
+ revive_hash(register(o, {}), o)
212
+ else
213
+ obj = revive((resolve_class(name) || class_loader.object), o)
214
+ obj
215
+ end
216
+
217
+ when /^!(?:str|ruby\/string)(?::(.*))?$/, 'tag:yaml.org,2002:str'
218
+ klass = resolve_class($1)
219
+ members = {}
220
+ string = nil
221
+
222
+ o.children.each_slice(2) do |k,v|
223
+ key = accept k
224
+ value = accept v
225
+
226
+ if key == 'str'
227
+ if klass
228
+ string = klass.allocate.replace value
229
+ else
230
+ string = value
231
+ end
232
+ register(o, string)
233
+ else
234
+ members[key] = value
235
+ end
236
+ end
237
+ init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
238
+ when /^!ruby\/array:(.*)$/
239
+ klass = resolve_class($1)
240
+ list = register(o, klass.allocate)
241
+
242
+ members = Hash[o.children.map { |c| accept c }.each_slice(2).to_a]
243
+ list.replace members['internal']
244
+
245
+ members['ivars'].each do |ivar, v|
246
+ list.instance_variable_set ivar, v
247
+ end
248
+ list
249
+
250
+ when '!ruby/range'
251
+ klass = class_loader.range
252
+ h = Hash[*o.children.map { |c| accept c }]
253
+ register o, klass.new(h['begin'], h['end'], h['excl'])
254
+
255
+ when /^!ruby\/exception:?(.*)?$/
256
+ h = Hash[*o.children.map { |c| accept c }]
257
+
258
+ e = build_exception((resolve_class($1) || class_loader.exception),
259
+ h.delete('message'))
260
+
261
+ e.set_backtrace h.delete('backtrace') if h.key? 'backtrace'
262
+ init_with(e, h, o)
263
+
264
+ when '!set', 'tag:yaml.org,2002:set'
265
+ set = class_loader.psych_set.new
266
+ @st[o.anchor] = set if o.anchor
267
+ o.children.each_slice(2) do |k,v|
268
+ set[accept(k)] = accept(v)
269
+ end
270
+ set
271
+
272
+ when /^!ruby\/hash-with-ivars(?::(.*))?$/
273
+ hash = $1 ? resolve_class($1).allocate : {}
274
+ register o, hash
275
+ o.children.each_slice(2) do |key, value|
276
+ case key.value
277
+ when 'elements'
278
+ revive_hash hash, value
279
+ when 'ivars'
280
+ value.children.each_slice(2) do |k,v|
281
+ hash.instance_variable_set accept(k), accept(v)
282
+ end
283
+ end
284
+ end
285
+ hash
286
+
287
+ when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/
288
+ revive_hash register(o, resolve_class($1).allocate), o
289
+
290
+ when '!omap', 'tag:yaml.org,2002:omap'
291
+ map = register(o, class_loader.psych_omap.new)
292
+ o.children.each_slice(2) do |l,r|
293
+ map[accept(l)] = accept r
294
+ end
295
+ map
296
+
297
+ when /^!ruby\/marshalable:(.*)$/
298
+ name = $1
299
+ klass = resolve_class(name)
300
+ obj = register(o, klass.allocate)
301
+
302
+ if obj.respond_to?(:init_with)
303
+ init_with(obj, revive_hash({}, o), o)
304
+ elsif obj.respond_to?(:marshal_load)
305
+ marshal_data = o.children.map(&method(:accept))
306
+ obj.marshal_load(marshal_data)
307
+ obj
308
+ else
309
+ raise ArgumentError, "Cannot deserialize #{name}"
310
+ end
311
+
312
+ else
313
+ revive_hash(register(o, {}), o)
314
+ end
315
+ end
316
+
317
+ def visit_Psych_Nodes_Document o
318
+ accept o.root
319
+ end
320
+
321
+ def visit_Psych_Nodes_Stream o
322
+ o.children.map { |c| accept c }
323
+ end
324
+
325
+ def visit_Psych_Nodes_Alias o
326
+ @st.fetch(o.anchor) { raise BadAlias, "Unknown alias: #{o.anchor}" }
327
+ end
328
+
329
+ private
330
+
331
+ def register node, object
332
+ @st[node.anchor] = object if node.anchor
333
+ object
334
+ end
335
+
336
+ def register_empty object
337
+ list = register(object, [])
338
+ object.children.each { |c| list.push accept c }
339
+ list
340
+ end
341
+
342
+ def revive_hash hash, o, tagged= false
343
+ o.children.each_slice(2) { |k,v|
344
+ key = accept(k)
345
+ val = accept(v)
346
+
347
+ if key == '<<' && k.tag != "tag:yaml.org,2002:str"
348
+ case v
349
+ when Nodes::Alias, Nodes::Mapping
350
+ begin
351
+ hash.merge! val
352
+ rescue TypeError
353
+ hash[key] = val
354
+ end
355
+ when Nodes::Sequence
356
+ begin
357
+ h = {}
358
+ val.reverse_each do |value|
359
+ h.merge! value
360
+ end
361
+ hash.merge! h
362
+ rescue TypeError
363
+ hash[key] = val
364
+ end
365
+ else
366
+ hash[key] = val
367
+ end
368
+ else
369
+ if !tagged && @symbolize_names && key.is_a?(String)
370
+ key = key.to_sym
371
+ elsif !@freeze
372
+ key = deduplicate(key)
373
+ end
374
+
375
+ hash[key] = val
376
+ end
377
+
378
+ }
379
+ hash
380
+ end
381
+
382
+ if RUBY_VERSION < '2.7'
383
+ def deduplicate key
384
+ if key.is_a?(String)
385
+ # It is important to untaint the string, otherwise it won't
386
+ # be deduplicated into an fstring, but simply frozen.
387
+ -(key.untaint)
388
+ else
389
+ key
390
+ end
391
+ end
392
+ else
393
+ def deduplicate key
394
+ if key.is_a?(String)
395
+ -key
396
+ else
397
+ key
398
+ end
399
+ end
400
+ end
401
+
402
+ def merge_key hash, key, val
403
+ end
404
+
405
+ def revive klass, node
406
+ s = register(node, klass.allocate)
407
+ init_with(s, revive_hash({}, node, true), node)
408
+ end
409
+
410
+ def init_with o, h, node
411
+ c = Psych::Coder.new(node.tag)
412
+ c.map = h
413
+
414
+ if o.respond_to?(:init_with)
415
+ o.init_with c
416
+ else
417
+ h.each { |k,v| o.instance_variable_set(:"@#{k}", v) }
418
+ end
419
+ o
420
+ end
421
+
422
+ # Convert +klassname+ to a Class
423
+ def resolve_class klassname
424
+ class_loader.load klassname
425
+ end
426
+ end
427
+
428
+ class NoAliasRuby < ToRuby
429
+ def visit_Psych_Nodes_Alias o
430
+ raise BadAlias, "Unknown alias: #{o.anchor}"
431
+ end
432
+ end
433
+ end
434
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ module Psych
3
+ module Visitors
4
+ class Visitor
5
+ def accept target
6
+ visit target
7
+ end
8
+
9
+ private
10
+
11
+ # @api private
12
+ def self.dispatch_cache
13
+ Hash.new do |hash, klass|
14
+ hash[klass] = :"visit_#{klass.name.gsub('::', '_')}"
15
+ end.compare_by_identity
16
+ end
17
+
18
+ if defined?(Ractor)
19
+ def dispatch
20
+ @dispatch_cache ||= (Ractor.current[:Psych_Visitors_Visitor] ||= Visitor.dispatch_cache)
21
+ end
22
+ else
23
+ DISPATCH = dispatch_cache
24
+ def dispatch
25
+ DISPATCH
26
+ end
27
+ end
28
+
29
+ def visit target
30
+ send dispatch[target.class], target
31
+ end
32
+ end
33
+ end
34
+ end