Sha256: bf99cb985a994657256ddfe9d4a7b68855a3892283b1f2ece1c354f92bb90845

Contents?: true

Size: 708 Bytes

Versions: 1

Compression:

Stored size: 708 Bytes

Contents

# frozen_string_literal: true

require "ruby-graphviz"
require "lutaml/layout/engine"

module Lutaml
  module Layout
    class GraphVizEngine < Engine
      def render(type)
        parse_graphviz_string
          .output(type => String)
      end

      private

      # GraphViz#parse_string and GraphViz#parse crush with no reason
      # with seg fault, this lead to nil return value.
      # Try to recall method several time
      def parse_graphviz_string(attempts = 10)
        raise('Cannot parse input string, `gvpr` segmentation fault?') if attempts == 0
        res = GraphViz.parse_string(input)
        return res if res

        parse_graphviz_string(attempts - 1)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lutaml-uml-0.2.1 lib/lutaml/layout/graph_viz_engine.rb