Class: Travis::Yaml::Serializer::Yaml

Inherits:
Ruby show all
Defined in:
lib/travis/yaml/serializer/yaml.rb

Defined Under Namespace

Classes: Tagged

Constant Summary collapse

PSYCH_OPTIONS =
[ :indentation, :line_width, :canonical ]

Instance Attribute Summary

Attributes inherited from Generic

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ruby

#serialize_mapping, #serialize_value

Methods inherited from Generic

#initialize, #serialize, #serialize_bool, #serialize_float, #serialize_key, #serialize_mapping, #serialize_regexp, #serialize_root, #serialize_scalar, #serialize_secure, #serialize_sequence, #serialize_str, #serialize_time, #serialize_value, #symbol_keys?

Constructor Details

This class inherits a constructor from Travis::Yaml::Serializer::Generic

Class Method Details

.serialize(node, options = nil) ⇒ Object



17
18
19
20
# File 'lib/travis/yaml/serializer/yaml.rb', line 17

def self.serialize(node, options = nil)
  psych_options = options.select { |key, _| PSYCH_OPTIONS.include? key } if options
  ::Psych.dump(super, psych_options || {})
end

Instance Method Details

#avoid_tags?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/travis/yaml/serializer/yaml.rb', line 22

def avoid_tags?
  !!options[:avoid_tags]
end

#serialize_binary(value) ⇒ Object



36
37
38
# File 'lib/travis/yaml/serializer/yaml.rb', line 36

def serialize_binary(value)
  Tagged.new('!binary', [value].pack('m0'))
end

#serialize_decrypted(value) ⇒ Object



31
32
33
34
# File 'lib/travis/yaml/serializer/yaml.rb', line 31

def serialize_decrypted(value)
  value = value.decrypted_string
  avoid_tags? ? value : Tagged.new('!decrypted', value)
end

#serialize_encrypted(value) ⇒ Object



26
27
28
29
# File 'lib/travis/yaml/serializer/yaml.rb', line 26

def serialize_encrypted(value)
  value = value.encrypted_string
  avoid_tags? ? { "secure" => value } : Tagged.new('!encrypted', value)
end