Class: Serialbench::Serializers::Yaml::SyckSerializer
Instance Method Summary
collapse
#default_generation_options, format, #stream_parse, #supports_generation?
#get_version, #initialize, #require_library, #stream_parse
Instance Method Details
#available? ⇒ Boolean
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 25
def available?
require 'syck'
return false unless defined?(Syck) && Syck.respond_to?(:dump) && Syck.respond_to?(:load)
if problematic_environment?
warn_about_segfault_issue
return false
end
true
rescue LoadError
false
end
|
#description ⇒ Object
79
80
81
|
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 79
def description
'Legacy YAML parser (Ruby < 1.9.3)'
end
|
#features ⇒ Object
75
76
77
|
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 75
def features
%w[parsing generation legacy]
end
|
#generate(object, _options = {}) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 56
def generate(object, _options = {})
return nil unless available?
begin
require 'syck'
Syck.dump(object)
rescue StandardError => e
if e.message.include?('Segmentation fault') || e.is_a?(SystemExit)
handle_segfault_error
return nil
end
raise e
end
end
|
#handle_segfault_error ⇒ Object
95
96
97
98
|
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 95
def handle_segfault_error
puts '❌ ERROR: Syck YAML serializer encountered a segmentation fault'
puts " This is a known issue on Ruby #{RUBY_VERSION}. Skipping remaining Syck tests."
end
|
#name ⇒ Object
9
10
11
|
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 9
def name
'syck'
end
|
#parse(yaml_string) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 41
def parse(yaml_string)
return nil unless available?
begin
require 'syck'
Syck.load(yaml_string)
rescue StandardError => e
if e.message.include?('Segmentation fault') || e.is_a?(SystemExit)
handle_segfault_error
return nil
end
raise e
end
end
|
#problematic_environment? ⇒ Boolean
83
84
85
86
87
|
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 83
def problematic_environment?
(Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')) &&
(Gem::Version.new(version) >= Gem::Version.new('1.4.0'))
end
|
#supports_streaming? ⇒ Boolean
71
72
73
|
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 71
def supports_streaming?
false
end
|
#version ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 13
def version
require 'syck'
spec = Gem.loaded_specs['syck']
return spec.version.to_s if spec
'1.0.0'
rescue StandardError
'N/A'
end
|
#warn_about_segfault_issue ⇒ Object
89
90
91
92
93
|
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 89
def warn_about_segfault_issue
puts "⚠️ WARNING: The Syck YAML serializer is known to cause segmentation faults with Ruby #{RUBY_VERSION}"
puts ' This is a known issue with the syck gem on newer Ruby versions systems.'
puts ' Skipping Syck benchmarks to prevent crashes. See README for more details.'
end
|