Class: Abroad::Extractors::Yaml::JRubyCompat

Inherits:
Object
  • Object
show all
Defined in:
lib/abroad/extractors/yaml/jruby_compat.rb

Overview

For some reason, Psych in MRI thinks it's valid yaml syntax to escape single quotes (surprise, it's not). This class is a performant way to identify and correct such invalid escaping. Be warned, it's a fairly naïve implementation.

NOTE: this technique will only work with YAML emitted in block mode, i.e. yaml that uses indentation and newlines for each key/value pair and array element

Constant Summary collapse

UNKNOWN_ESCAPE_MSG =
"found unknown escape character '(39)"
UNEXPECTED_EOS_MSG =
'found unexpected end of stream while scanning a quoted scalar'

Class Method Summary collapse

Class Method Details

.clean(yaml_content) ⇒ Object


22
23
24
25
26
27
28
29
# File 'lib/abroad/extractors/yaml/jruby_compat.rb', line 22

def clean(yaml_content)
  # convert to java string for performance reasons (don't have to
  # coerce/convert from java to ruby and back again)
  # https://github.com/jruby/jruby/wiki/ImprovingJavaIntegrationPerformance#pre-coerce-values-used-repeatedly
  yaml_content = yaml_content.to_java
  ranges = identify_ranges(yaml_content)
  reconstruct(yaml_content, ranges)
end