cybrid_api_organization_ruby 0.8.12 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +5 -5
- data/cybrid_api_organization_ruby.gemspec +1 -1
- data/lib/cybrid_api_organization_ruby/api/organizations_organization_api.rb +1 -1
- data/lib/cybrid_api_organization_ruby/api_client.rb +1 -1
- data/lib/cybrid_api_organization_ruby/api_error.rb +1 -1
- data/lib/cybrid_api_organization_ruby/configuration.rb +1 -1
- data/lib/cybrid_api_organization_ruby/models/error_response_organization_model.rb +1 -1
- data/lib/cybrid_api_organization_ruby/models/organization_organization_model.rb +1 -1
- data/lib/cybrid_api_organization_ruby/models/patch_organization_organization_model.rb +1 -1
- data/lib/cybrid_api_organization_ruby/version.rb +2 -2
- data/lib/cybrid_api_organization_ruby.rb +1 -1
- data/spec/api/organizations_organization_api_spec.rb +1 -1
- data/spec/api_client_spec.rb +1 -1
- data/spec/configuration_spec.rb +1 -1
- data/spec/models/error_response_organization_model_spec.rb +1 -1
- data/spec/models/organization_organization_model_spec.rb +1 -1
- data/spec/models/patch_organization_organization_model_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/vendor/bundle/ruby/3.1.0/cache/psych-4.0.4.gem +0 -0
- data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/byebug-11.1.3/gem_make.out +2 -2
- data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/ffi-1.15.5/gem_make.out +2 -2
- 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
- data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/psych-4.0.4/gem.build_complete +0 -0
- data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/psych-4.0.4/gem_make.out +27 -0
- data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/psych-4.0.4/mkmf.log +75 -0
- data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/psych-4.0.4/psych.so +0 -0
- data/vendor/bundle/ruby/3.1.0/extensions/x86_64-linux/3.1.0-static/stringio-3.0.2/gem_make.out +2 -2
- data/vendor/bundle/ruby/3.1.0/gems/byebug-11.1.3/ext/byebug/Makefile +2 -2
- data/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/ext/ffi_c/Makefile +2 -2
- data/vendor/bundle/ruby/3.1.0/gems/jaro_winkler-1.5.4/ext/jaro_winkler/Makefile +2 -2
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/.gitignore +16 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/Gemfile +9 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/LICENSE +21 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/Mavenfile +7 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/README.md +72 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/Rakefile +41 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/bin/console +7 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/bin/setup +6 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/.sitearchdir.time +0 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/Makefile +274 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/depend +5 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/extconf.rb +43 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych.c +37 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych.h +17 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych.o +0 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych.so +0 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_emitter.c +555 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_emitter.h +8 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_emitter.o +0 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_parser.c +579 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_parser.h +6 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_parser.o +0 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_to_ruby.c +39 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_to_ruby.h +8 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_to_ruby.o +0 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_yaml_tree.c +12 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_yaml_tree.h +8 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/psych_yaml_tree.o +0 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/LICENSE +19 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/api.c +1393 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/config.h +80 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/dumper.c +394 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/emitter.c +2358 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/loader.c +544 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/parser.c +1375 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/reader.c +469 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/scanner.c +3598 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/writer.c +141 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/yaml.h +1985 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/ext/psych/yaml/yaml_private.h +688 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/class_loader.rb +104 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/coder.rb +95 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/core_ext.rb +19 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/exception.rb +14 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/handler.rb +255 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/handlers/document_stream.rb +23 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/handlers/recorder.rb +40 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/json/ruby_events.rb +20 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/json/stream.rb +17 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/json/tree_builder.rb +13 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/json/yaml_events.rb +30 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/alias.rb +21 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/document.rb +63 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/mapping.rb +59 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/node.rb +75 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/scalar.rb +70 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/sequence.rb +84 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes/stream.rb +40 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/nodes.rb +78 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/omap.rb +5 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/parser.rb +52 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/scalar_scanner.rb +142 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/set.rb +5 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/stream.rb +38 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/streaming.rb +28 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/syntax_error.rb +22 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/tree_builder.rb +137 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/versions.rb +10 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/depth_first.rb +27 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/emitter.rb +52 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/json_tree.rb +25 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb +434 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/visitor.rb +34 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors/yaml_tree.rb +587 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/visitors.rb +7 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych/y.rb +10 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych.rb +741 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/lib/psych.so +0 -0
- data/vendor/bundle/ruby/3.1.0/gems/psych-4.0.4/psych.gemspec +69 -0
- data/vendor/bundle/ruby/3.1.0/gems/stringio-3.0.2/ext/stringio/Makefile +2 -2
- data/vendor/bundle/ruby/3.1.0/specifications/psych-4.0.4.gemspec +36 -0
- 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
|