Class: FlakyTestTracker::Serializers::HTMLCommentSerializer
- Inherits:
-
Object
- Object
- FlakyTestTracker::Serializers::HTMLCommentSerializer
- Defined in:
- lib/flaky_test_tracker/serializers/html_comment_serializer.rb
Overview
HTML comment serializer.
It encodes the value in base64 because an HTML comment content can't:
- start with: ">" nor "->";
- contain: "--".
Instance Method Summary collapse
-
#deserialize(value) ⇒ String
The value to deserialized.
-
#serialize(value) ⇒ String
The value to serialized as HTML comment.
Instance Method Details
#deserialize(value) ⇒ String
Returns the value to deserialized.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/flaky_test_tracker/serializers/html_comment_serializer.rb', line 30 def deserialize(value) parser = Oga::XML::Parser.new(value, html: true) document = parser.parse comment = document.xpath(".//comment()").first raise FlakyTestTracker::Error::DeserializeError unless comment Base64.strict_decode64(comment.text.strip) rescue ArgumentError, LL::ParserError raise FlakyTestTracker::Error::DeserializeError end |
#serialize(value) ⇒ String
Returns the value to serialized as HTML comment.
18 19 20 21 22 23 24 25 |
# File 'lib/flaky_test_tracker/serializers/html_comment_serializer.rb', line 18 def serialize(value) # We need to base64 encode since comment: # - can't start with: `>` or `->` # - can't include: `--` content = Base64.strict_encode64(value) comment = Oga::XML::Comment.new(text: content) comment.to_xml end |