Sha256: 4feb92812ef9d3817ce55be9334f36261d3eb82a4564a4068597cba0ab223fa5

Contents?: true

Size: 624 Bytes

Versions: 26

Compression:

Stored size: 624 Bytes

Contents

require "json"
require "yaml"

module Kubes::Compiler::Util
  module YamlDump
    def yaml_dump(data)
      case data
      when Array
        items = data.map do |i|
          standardize_yaml(i)
        end
        items.map(&:to_yaml).join("")
      else # single resource in YAML
        data = standardize_yaml(data)
        data.to_yaml
      end
    end

    # https://stackoverflow.com/questions/24508364/how-to-emit-yaml-in-ruby-expanding-aliases/46104244#46104244
    # Prevents YAML from generating aliases/anchors.
    def standardize_yaml(data)
      json = data.to_json
      YAML.load(json)
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
kubes-0.9.3 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.9.2 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.9.1 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.9.0 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.8.10 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.8.9 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.8.8 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.8.7 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.8.6 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.8.5 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.8.4 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.8.3 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.8.2 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.8.1 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.8.0 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.7.10 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.7.9 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.7.8 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.7.7 lib/kubes/compiler/util/yaml_dump.rb
kubes-0.7.6 lib/kubes/compiler/util/yaml_dump.rb