cybrid_api_id_ruby 0.9.0 → 0.9.1
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_id_ruby.gemspec +1 -1
- data/lib/cybrid_api_id_ruby/api/bank_applications_idp_api.rb +1 -1
- data/lib/cybrid_api_id_ruby/api/organization_applications_idp_api.rb +1 -1
- data/lib/cybrid_api_id_ruby/api_client.rb +1 -1
- data/lib/cybrid_api_id_ruby/api_error.rb +1 -1
- data/lib/cybrid_api_id_ruby/configuration.rb +1 -1
- data/lib/cybrid_api_id_ruby/models/application_idp_model.rb +1 -1
- data/lib/cybrid_api_id_ruby/models/application_list_idp_model.rb +1 -1
- data/lib/cybrid_api_id_ruby/models/application_with_secret_all_of_idp_model.rb +1 -1
- data/lib/cybrid_api_id_ruby/models/application_with_secret_idp_model.rb +1 -1
- data/lib/cybrid_api_id_ruby/models/post_bank_application_idp_model.rb +1 -1
- data/lib/cybrid_api_id_ruby/models/post_organization_application_idp_model.rb +1 -1
- data/lib/cybrid_api_id_ruby/version.rb +2 -2
- data/lib/cybrid_api_id_ruby.rb +1 -1
- data/spec/api/bank_applications_idp_api_spec.rb +1 -1
- data/spec/api/organization_applications_idp_api_spec.rb +1 -1
- data/spec/api_client_spec.rb +1 -1
- data/spec/configuration_spec.rb +1 -1
- data/spec/models/application_idp_model_spec.rb +1 -1
- data/spec/models/application_list_idp_model_spec.rb +1 -1
- data/spec/models/application_with_secret_all_of_idp_model_spec.rb +1 -1
- data/spec/models/application_with_secret_idp_model_spec.rb +1 -1
- data/spec/models/post_bank_application_idp_model_spec.rb +1 -1
- data/spec/models/post_organization_application_idp_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 +86 -1
@@ -0,0 +1,587 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative '../tree_builder'
|
3
|
+
require_relative '../scalar_scanner'
|
4
|
+
require_relative '../class_loader'
|
5
|
+
|
6
|
+
module Psych
|
7
|
+
module Visitors
|
8
|
+
###
|
9
|
+
# YAMLTree builds a YAML ast given a Ruby object. For example:
|
10
|
+
#
|
11
|
+
# builder = Psych::Visitors::YAMLTree.new
|
12
|
+
# builder << { :foo => 'bar' }
|
13
|
+
# builder.tree # => #<Psych::Nodes::Stream .. }
|
14
|
+
#
|
15
|
+
class YAMLTree < Psych::Visitors::Visitor
|
16
|
+
class Registrar # :nodoc:
|
17
|
+
def initialize
|
18
|
+
@obj_to_id = {}
|
19
|
+
@obj_to_node = {}
|
20
|
+
@targets = []
|
21
|
+
@counter = 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def register target, node
|
25
|
+
return unless target.respond_to? :object_id
|
26
|
+
@targets << target
|
27
|
+
@obj_to_node[target.object_id] = node
|
28
|
+
end
|
29
|
+
|
30
|
+
def key? target
|
31
|
+
@obj_to_node.key? target.object_id
|
32
|
+
rescue NoMethodError
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
def id_for target
|
37
|
+
@obj_to_id[target.object_id] ||= (@counter += 1)
|
38
|
+
end
|
39
|
+
|
40
|
+
def node_for target
|
41
|
+
@obj_to_node[target.object_id]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_reader :started, :finished
|
46
|
+
alias :finished? :finished
|
47
|
+
alias :started? :started
|
48
|
+
|
49
|
+
def self.create options = {}, emitter = nil
|
50
|
+
emitter ||= TreeBuilder.new
|
51
|
+
class_loader = ClassLoader.new
|
52
|
+
ss = ScalarScanner.new class_loader
|
53
|
+
new(emitter, ss, options)
|
54
|
+
end
|
55
|
+
|
56
|
+
def initialize emitter, ss, options
|
57
|
+
super()
|
58
|
+
@started = false
|
59
|
+
@finished = false
|
60
|
+
@emitter = emitter
|
61
|
+
@st = Registrar.new
|
62
|
+
@ss = ss
|
63
|
+
@options = options
|
64
|
+
@line_width = options[:line_width]
|
65
|
+
if @line_width && @line_width < 0
|
66
|
+
if @line_width == -1
|
67
|
+
# Treat -1 as unlimited line-width, same as libyaml does.
|
68
|
+
@line_width = nil
|
69
|
+
else
|
70
|
+
fail(ArgumentError, "Invalid line_width #{@line_width}, must be non-negative or -1 for unlimited.")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
@coders = []
|
74
|
+
|
75
|
+
@dispatch_cache = Hash.new do |h,klass|
|
76
|
+
method = "visit_#{(klass.name || '').split('::').join('_')}"
|
77
|
+
|
78
|
+
method = respond_to?(method) ? method : h[klass.superclass]
|
79
|
+
|
80
|
+
raise(TypeError, "Can't dump #{target.class}") unless method
|
81
|
+
|
82
|
+
h[klass] = method
|
83
|
+
end.compare_by_identity
|
84
|
+
end
|
85
|
+
|
86
|
+
def start encoding = Nodes::Stream::UTF8
|
87
|
+
@emitter.start_stream(encoding).tap do
|
88
|
+
@started = true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def finish
|
93
|
+
@emitter.end_stream.tap do
|
94
|
+
@finished = true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def tree
|
99
|
+
finish unless finished?
|
100
|
+
@emitter.root
|
101
|
+
end
|
102
|
+
|
103
|
+
def push object
|
104
|
+
start unless started?
|
105
|
+
version = []
|
106
|
+
version = [1,1] if @options[:header]
|
107
|
+
|
108
|
+
case @options[:version]
|
109
|
+
when Array
|
110
|
+
version = @options[:version]
|
111
|
+
when String
|
112
|
+
version = @options[:version].split('.').map { |x| x.to_i }
|
113
|
+
else
|
114
|
+
version = [1,1]
|
115
|
+
end if @options.key? :version
|
116
|
+
|
117
|
+
@emitter.start_document version, [], false
|
118
|
+
accept object
|
119
|
+
@emitter.end_document !@emitter.streaming?
|
120
|
+
end
|
121
|
+
alias :<< :push
|
122
|
+
|
123
|
+
def accept target
|
124
|
+
# return any aliases we find
|
125
|
+
if @st.key? target
|
126
|
+
oid = @st.id_for target
|
127
|
+
node = @st.node_for target
|
128
|
+
anchor = oid.to_s
|
129
|
+
node.anchor = anchor
|
130
|
+
return @emitter.alias anchor
|
131
|
+
end
|
132
|
+
|
133
|
+
if target.respond_to?(:encode_with)
|
134
|
+
dump_coder target
|
135
|
+
else
|
136
|
+
send(@dispatch_cache[target.class], target)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def visit_Psych_Omap o
|
141
|
+
seq = @emitter.start_sequence(nil, 'tag:yaml.org,2002:omap', false, Nodes::Sequence::BLOCK)
|
142
|
+
register(o, seq)
|
143
|
+
|
144
|
+
o.each { |k,v| visit_Hash k => v }
|
145
|
+
@emitter.end_sequence
|
146
|
+
end
|
147
|
+
|
148
|
+
def visit_Encoding o
|
149
|
+
tag = "!ruby/encoding"
|
150
|
+
@emitter.scalar o.name, nil, tag, false, false, Nodes::Scalar::ANY
|
151
|
+
end
|
152
|
+
|
153
|
+
def visit_Object o
|
154
|
+
tag = Psych.dump_tags[o.class]
|
155
|
+
unless tag
|
156
|
+
klass = o.class == Object ? nil : o.class.name
|
157
|
+
tag = ['!ruby/object', klass].compact.join(':')
|
158
|
+
end
|
159
|
+
|
160
|
+
map = @emitter.start_mapping(nil, tag, false, Nodes::Mapping::BLOCK)
|
161
|
+
register(o, map)
|
162
|
+
|
163
|
+
dump_ivars o
|
164
|
+
@emitter.end_mapping
|
165
|
+
end
|
166
|
+
|
167
|
+
alias :visit_Delegator :visit_Object
|
168
|
+
|
169
|
+
def visit_Struct o
|
170
|
+
tag = ['!ruby/struct', o.class.name].compact.join(':')
|
171
|
+
|
172
|
+
register o, @emitter.start_mapping(nil, tag, false, Nodes::Mapping::BLOCK)
|
173
|
+
o.members.each do |member|
|
174
|
+
@emitter.scalar member.to_s, nil, nil, true, false, Nodes::Scalar::ANY
|
175
|
+
accept o[member]
|
176
|
+
end
|
177
|
+
|
178
|
+
dump_ivars o
|
179
|
+
|
180
|
+
@emitter.end_mapping
|
181
|
+
end
|
182
|
+
|
183
|
+
def visit_Exception o
|
184
|
+
dump_exception o, o.message.to_s
|
185
|
+
end
|
186
|
+
|
187
|
+
def visit_NameError o
|
188
|
+
dump_exception o, o.message.to_s
|
189
|
+
end
|
190
|
+
|
191
|
+
def visit_Regexp o
|
192
|
+
register o, @emitter.scalar(o.inspect, nil, '!ruby/regexp', false, false, Nodes::Scalar::ANY)
|
193
|
+
end
|
194
|
+
|
195
|
+
def visit_DateTime o
|
196
|
+
formatted = if o.offset.zero?
|
197
|
+
o.strftime("%Y-%m-%d %H:%M:%S.%9N Z".freeze)
|
198
|
+
else
|
199
|
+
o.strftime("%Y-%m-%d %H:%M:%S.%9N %:z".freeze)
|
200
|
+
end
|
201
|
+
tag = '!ruby/object:DateTime'
|
202
|
+
register o, @emitter.scalar(formatted, nil, tag, false, false, Nodes::Scalar::ANY)
|
203
|
+
end
|
204
|
+
|
205
|
+
def visit_Time o
|
206
|
+
formatted = format_time o
|
207
|
+
register o, @emitter.scalar(formatted, nil, nil, true, false, Nodes::Scalar::ANY)
|
208
|
+
end
|
209
|
+
|
210
|
+
def visit_Rational o
|
211
|
+
register o, @emitter.start_mapping(nil, '!ruby/object:Rational', false, Nodes::Mapping::BLOCK)
|
212
|
+
|
213
|
+
[
|
214
|
+
'denominator', o.denominator.to_s,
|
215
|
+
'numerator', o.numerator.to_s
|
216
|
+
].each do |m|
|
217
|
+
@emitter.scalar m, nil, nil, true, false, Nodes::Scalar::ANY
|
218
|
+
end
|
219
|
+
|
220
|
+
@emitter.end_mapping
|
221
|
+
end
|
222
|
+
|
223
|
+
def visit_Complex o
|
224
|
+
register o, @emitter.start_mapping(nil, '!ruby/object:Complex', false, Nodes::Mapping::BLOCK)
|
225
|
+
|
226
|
+
['real', o.real.to_s, 'image', o.imag.to_s].each do |m|
|
227
|
+
@emitter.scalar m, nil, nil, true, false, Nodes::Scalar::ANY
|
228
|
+
end
|
229
|
+
|
230
|
+
@emitter.end_mapping
|
231
|
+
end
|
232
|
+
|
233
|
+
def visit_Integer o
|
234
|
+
@emitter.scalar o.to_s, nil, nil, true, false, Nodes::Scalar::ANY
|
235
|
+
end
|
236
|
+
alias :visit_TrueClass :visit_Integer
|
237
|
+
alias :visit_FalseClass :visit_Integer
|
238
|
+
alias :visit_Date :visit_Integer
|
239
|
+
|
240
|
+
def visit_Float o
|
241
|
+
if o.nan?
|
242
|
+
@emitter.scalar '.nan', nil, nil, true, false, Nodes::Scalar::ANY
|
243
|
+
elsif o.infinite?
|
244
|
+
@emitter.scalar((o.infinite? > 0 ? '.inf' : '-.inf'),
|
245
|
+
nil, nil, true, false, Nodes::Scalar::ANY)
|
246
|
+
else
|
247
|
+
@emitter.scalar o.to_s, nil, nil, true, false, Nodes::Scalar::ANY
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def visit_BigDecimal o
|
252
|
+
@emitter.scalar o._dump, nil, '!ruby/object:BigDecimal', false, false, Nodes::Scalar::ANY
|
253
|
+
end
|
254
|
+
|
255
|
+
def visit_String o
|
256
|
+
plain = true
|
257
|
+
quote = true
|
258
|
+
style = Nodes::Scalar::PLAIN
|
259
|
+
tag = nil
|
260
|
+
|
261
|
+
if binary?(o)
|
262
|
+
o = [o].pack('m0')
|
263
|
+
tag = '!binary' # FIXME: change to below when syck is removed
|
264
|
+
#tag = 'tag:yaml.org,2002:binary'
|
265
|
+
style = Nodes::Scalar::LITERAL
|
266
|
+
plain = false
|
267
|
+
quote = false
|
268
|
+
elsif o =~ /\n(?!\Z)/ # match \n except blank line at the end of string
|
269
|
+
style = Nodes::Scalar::LITERAL
|
270
|
+
elsif o == '<<'
|
271
|
+
style = Nodes::Scalar::SINGLE_QUOTED
|
272
|
+
tag = 'tag:yaml.org,2002:str'
|
273
|
+
plain = false
|
274
|
+
quote = false
|
275
|
+
elsif o == 'y' || o == 'n'
|
276
|
+
style = Nodes::Scalar::DOUBLE_QUOTED
|
277
|
+
elsif @line_width && o.length > @line_width
|
278
|
+
style = Nodes::Scalar::FOLDED
|
279
|
+
elsif o =~ /^[^[:word:]][^"]*$/
|
280
|
+
style = Nodes::Scalar::DOUBLE_QUOTED
|
281
|
+
elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/ =~ o
|
282
|
+
style = Nodes::Scalar::SINGLE_QUOTED
|
283
|
+
end
|
284
|
+
|
285
|
+
is_primitive = o.class == ::String
|
286
|
+
ivars = is_primitive ? [] : o.instance_variables
|
287
|
+
|
288
|
+
if ivars.empty?
|
289
|
+
unless is_primitive
|
290
|
+
tag = "!ruby/string:#{o.class}"
|
291
|
+
plain = false
|
292
|
+
quote = false
|
293
|
+
end
|
294
|
+
@emitter.scalar o, nil, tag, plain, quote, style
|
295
|
+
else
|
296
|
+
maptag = '!ruby/string'.dup
|
297
|
+
maptag << ":#{o.class}" unless o.class == ::String
|
298
|
+
|
299
|
+
register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
|
300
|
+
@emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY
|
301
|
+
@emitter.scalar o, nil, tag, plain, quote, style
|
302
|
+
|
303
|
+
dump_ivars o
|
304
|
+
|
305
|
+
@emitter.end_mapping
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
def visit_Module o
|
310
|
+
raise TypeError, "can't dump anonymous module: #{o}" unless o.name
|
311
|
+
register o, @emitter.scalar(o.name, nil, '!ruby/module', false, false, Nodes::Scalar::SINGLE_QUOTED)
|
312
|
+
end
|
313
|
+
|
314
|
+
def visit_Class o
|
315
|
+
raise TypeError, "can't dump anonymous class: #{o}" unless o.name
|
316
|
+
register o, @emitter.scalar(o.name, nil, '!ruby/class', false, false, Nodes::Scalar::SINGLE_QUOTED)
|
317
|
+
end
|
318
|
+
|
319
|
+
def visit_Range o
|
320
|
+
register o, @emitter.start_mapping(nil, '!ruby/range', false, Nodes::Mapping::BLOCK)
|
321
|
+
['begin', o.begin, 'end', o.end, 'excl', o.exclude_end?].each do |m|
|
322
|
+
accept m
|
323
|
+
end
|
324
|
+
@emitter.end_mapping
|
325
|
+
end
|
326
|
+
|
327
|
+
def visit_Hash o
|
328
|
+
if o.class == ::Hash
|
329
|
+
register(o, @emitter.start_mapping(nil, nil, true, Psych::Nodes::Mapping::BLOCK))
|
330
|
+
o.each do |k,v|
|
331
|
+
accept k
|
332
|
+
accept v
|
333
|
+
end
|
334
|
+
@emitter.end_mapping
|
335
|
+
else
|
336
|
+
visit_hash_subclass o
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def visit_Psych_Set o
|
341
|
+
register(o, @emitter.start_mapping(nil, '!set', false, Psych::Nodes::Mapping::BLOCK))
|
342
|
+
|
343
|
+
o.each do |k,v|
|
344
|
+
accept k
|
345
|
+
accept v
|
346
|
+
end
|
347
|
+
|
348
|
+
@emitter.end_mapping
|
349
|
+
end
|
350
|
+
|
351
|
+
def visit_Array o
|
352
|
+
if o.class == ::Array
|
353
|
+
visit_Enumerator o
|
354
|
+
else
|
355
|
+
visit_array_subclass o
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
def visit_Enumerator o
|
360
|
+
register o, @emitter.start_sequence(nil, nil, true, Nodes::Sequence::BLOCK)
|
361
|
+
o.each { |c| accept c }
|
362
|
+
@emitter.end_sequence
|
363
|
+
end
|
364
|
+
|
365
|
+
def visit_NilClass o
|
366
|
+
@emitter.scalar('', nil, 'tag:yaml.org,2002:null', true, false, Nodes::Scalar::ANY)
|
367
|
+
end
|
368
|
+
|
369
|
+
def visit_Symbol o
|
370
|
+
if o.empty?
|
371
|
+
@emitter.scalar "", nil, '!ruby/symbol', false, false, Nodes::Scalar::ANY
|
372
|
+
else
|
373
|
+
@emitter.scalar ":#{o}", nil, nil, true, false, Nodes::Scalar::ANY
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
def visit_BasicObject o
|
378
|
+
tag = Psych.dump_tags[o.class]
|
379
|
+
tag ||= "!ruby/marshalable:#{o.class.name}"
|
380
|
+
|
381
|
+
map = @emitter.start_mapping(nil, tag, false, Nodes::Mapping::BLOCK)
|
382
|
+
register(o, map)
|
383
|
+
|
384
|
+
o.marshal_dump.each(&method(:accept))
|
385
|
+
|
386
|
+
@emitter.end_mapping
|
387
|
+
end
|
388
|
+
|
389
|
+
private
|
390
|
+
|
391
|
+
def binary? string
|
392
|
+
string.encoding == Encoding::ASCII_8BIT && !string.ascii_only?
|
393
|
+
end
|
394
|
+
|
395
|
+
def visit_array_subclass o
|
396
|
+
tag = "!ruby/array:#{o.class}"
|
397
|
+
ivars = o.instance_variables
|
398
|
+
if ivars.empty?
|
399
|
+
node = @emitter.start_sequence(nil, tag, false, Nodes::Sequence::BLOCK)
|
400
|
+
register o, node
|
401
|
+
o.each { |c| accept c }
|
402
|
+
@emitter.end_sequence
|
403
|
+
else
|
404
|
+
node = @emitter.start_mapping(nil, tag, false, Nodes::Sequence::BLOCK)
|
405
|
+
register o, node
|
406
|
+
|
407
|
+
# Dump the internal list
|
408
|
+
accept 'internal'
|
409
|
+
@emitter.start_sequence(nil, nil, true, Nodes::Sequence::BLOCK)
|
410
|
+
o.each { |c| accept c }
|
411
|
+
@emitter.end_sequence
|
412
|
+
|
413
|
+
# Dump the ivars
|
414
|
+
accept 'ivars'
|
415
|
+
@emitter.start_mapping(nil, nil, true, Nodes::Sequence::BLOCK)
|
416
|
+
ivars.each do |ivar|
|
417
|
+
accept ivar
|
418
|
+
accept o.instance_variable_get ivar
|
419
|
+
end
|
420
|
+
@emitter.end_mapping
|
421
|
+
|
422
|
+
@emitter.end_mapping
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
def visit_hash_subclass o
|
427
|
+
ivars = o.instance_variables
|
428
|
+
if ivars.any?
|
429
|
+
tag = "!ruby/hash-with-ivars:#{o.class}"
|
430
|
+
node = @emitter.start_mapping(nil, tag, false, Psych::Nodes::Mapping::BLOCK)
|
431
|
+
register(o, node)
|
432
|
+
|
433
|
+
# Dump the ivars
|
434
|
+
accept 'ivars'
|
435
|
+
@emitter.start_mapping nil, nil, true, Nodes::Mapping::BLOCK
|
436
|
+
o.instance_variables.each do |ivar|
|
437
|
+
accept ivar
|
438
|
+
accept o.instance_variable_get ivar
|
439
|
+
end
|
440
|
+
@emitter.end_mapping
|
441
|
+
|
442
|
+
# Dump the elements
|
443
|
+
accept 'elements'
|
444
|
+
@emitter.start_mapping nil, nil, true, Nodes::Mapping::BLOCK
|
445
|
+
o.each do |k,v|
|
446
|
+
accept k
|
447
|
+
accept v
|
448
|
+
end
|
449
|
+
@emitter.end_mapping
|
450
|
+
|
451
|
+
@emitter.end_mapping
|
452
|
+
else
|
453
|
+
tag = "!ruby/hash:#{o.class}"
|
454
|
+
node = @emitter.start_mapping(nil, tag, false, Psych::Nodes::Mapping::BLOCK)
|
455
|
+
register(o, node)
|
456
|
+
o.each do |k,v|
|
457
|
+
accept k
|
458
|
+
accept v
|
459
|
+
end
|
460
|
+
@emitter.end_mapping
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
def dump_list o
|
465
|
+
end
|
466
|
+
|
467
|
+
def dump_exception o, msg
|
468
|
+
tag = ['!ruby/exception', o.class.name].join ':'
|
469
|
+
|
470
|
+
@emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
|
471
|
+
|
472
|
+
if msg
|
473
|
+
@emitter.scalar 'message', nil, nil, true, false, Nodes::Scalar::ANY
|
474
|
+
accept msg
|
475
|
+
end
|
476
|
+
|
477
|
+
@emitter.scalar 'backtrace', nil, nil, true, false, Nodes::Scalar::ANY
|
478
|
+
accept o.backtrace
|
479
|
+
|
480
|
+
dump_ivars o
|
481
|
+
|
482
|
+
@emitter.end_mapping
|
483
|
+
end
|
484
|
+
|
485
|
+
def format_time time
|
486
|
+
if time.utc?
|
487
|
+
time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
|
488
|
+
else
|
489
|
+
time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
def register target, yaml_obj
|
494
|
+
@st.register target, yaml_obj
|
495
|
+
yaml_obj
|
496
|
+
end
|
497
|
+
|
498
|
+
def dump_coder o
|
499
|
+
@coders << o
|
500
|
+
tag = Psych.dump_tags[o.class]
|
501
|
+
unless tag
|
502
|
+
klass = o.class == Object ? nil : o.class.name
|
503
|
+
tag = ['!ruby/object', klass].compact.join(':')
|
504
|
+
end
|
505
|
+
|
506
|
+
c = Psych::Coder.new(tag)
|
507
|
+
o.encode_with(c)
|
508
|
+
emit_coder c, o
|
509
|
+
end
|
510
|
+
|
511
|
+
def emit_coder c, o
|
512
|
+
case c.type
|
513
|
+
when :scalar
|
514
|
+
@emitter.scalar c.scalar, nil, c.tag, c.tag.nil?, false, c.style
|
515
|
+
when :seq
|
516
|
+
@emitter.start_sequence nil, c.tag, c.tag.nil?, c.style
|
517
|
+
c.seq.each do |thing|
|
518
|
+
accept thing
|
519
|
+
end
|
520
|
+
@emitter.end_sequence
|
521
|
+
when :map
|
522
|
+
register o, @emitter.start_mapping(nil, c.tag, c.implicit, c.style)
|
523
|
+
c.map.each do |k,v|
|
524
|
+
accept k
|
525
|
+
accept v
|
526
|
+
end
|
527
|
+
@emitter.end_mapping
|
528
|
+
when :object
|
529
|
+
accept c.object
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
def dump_ivars target
|
534
|
+
target.instance_variables.each do |iv|
|
535
|
+
@emitter.scalar("#{iv.to_s.sub(/^@/, '')}", nil, nil, true, false, Nodes::Scalar::ANY)
|
536
|
+
accept target.instance_variable_get(iv)
|
537
|
+
end
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
class RestrictedYAMLTree < YAMLTree
|
542
|
+
DEFAULT_PERMITTED_CLASSES = {
|
543
|
+
TrueClass => true,
|
544
|
+
FalseClass => true,
|
545
|
+
NilClass => true,
|
546
|
+
Integer => true,
|
547
|
+
Float => true,
|
548
|
+
String => true,
|
549
|
+
Array => true,
|
550
|
+
Hash => true,
|
551
|
+
}.compare_by_identity.freeze
|
552
|
+
|
553
|
+
def initialize emitter, ss, options
|
554
|
+
super
|
555
|
+
@permitted_classes = DEFAULT_PERMITTED_CLASSES.dup
|
556
|
+
Array(options[:permitted_classes]).each do |klass|
|
557
|
+
@permitted_classes[klass] = true
|
558
|
+
end
|
559
|
+
@permitted_symbols = {}.compare_by_identity
|
560
|
+
Array(options[:permitted_symbols]).each do |symbol|
|
561
|
+
@permitted_symbols[symbol] = true
|
562
|
+
end
|
563
|
+
@aliases = options.fetch(:aliases, false)
|
564
|
+
end
|
565
|
+
|
566
|
+
def accept target
|
567
|
+
if !@aliases && @st.key?(target)
|
568
|
+
raise BadAlias, "Tried to dump an aliased object"
|
569
|
+
end
|
570
|
+
|
571
|
+
unless @permitted_classes[target.class]
|
572
|
+
raise DisallowedClass.new('dump', target.class.name || target.class.inspect)
|
573
|
+
end
|
574
|
+
|
575
|
+
super
|
576
|
+
end
|
577
|
+
|
578
|
+
def visit_Symbol sym
|
579
|
+
unless @permitted_symbols[sym]
|
580
|
+
raise DisallowedClass.new('dump', "Symbol(#{sym.inspect})")
|
581
|
+
end
|
582
|
+
|
583
|
+
super
|
584
|
+
end
|
585
|
+
end
|
586
|
+
end
|
587
|
+
end
|