Sha256: fadede96fca7ef34ef529c2ba4e9a505a925a79fd681f3bb75e5114604a1e244

Contents?: true

Size: 1.34 KB

Versions: 10

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'set'

module CycloneLariat
  module Presenters
    class Graph
      HEADS = %w[topic endpoint subscription_arn].freeze
      def self.call(subscriptions)
        new.call(subscriptions)
      end

      def call(subscriptions)
        return '' if subscriptions.empty?

        resources_set = Set.new

        subscriptions.each do |subscription|
          resources_set << subscription[:topic]
          resources_set << subscription[:endpoint]
        end

        [].tap do |output|
          output << open_graph

          resources_set.each { |resource| output << present_resource(resource) }
          subscriptions.each { |subscription| output << present_subscription(subscription) }

          output << close_graph
        end
      end

      private

      def present_resource(resource)
        color = resource.custom? ? ', fillcolor=grey' : ', fillcolor=white'
        style = resource.topic? ? "[shape=component style=filled#{color}]" : "[shape=record, style=\"rounded,filled\"#{color}]"
        "  \"#{resource.name}\" #{style};"
      end

      def present_subscription(subscription)
        "  \"#{subscription[:topic].name}\" -> \"#{subscription[:endpoint].name}\";"
      end

      def open_graph
        "digraph G {\n  rankdir=LR;"
      end

      def close_graph
        '}'
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cyclone_lariat-1.0.0 lib/cyclone_lariat/presenters/graph.rb
cyclone_lariat-1.0.0.rc9 lib/cyclone_lariat/presenters/graph.rb
cyclone_lariat-1.0.0.rc8 lib/cyclone_lariat/presenters/graph.rb
cyclone_lariat-1.0.0.rc7 lib/cyclone_lariat/presenters/graph.rb
cyclone_lariat-1.0.0.rc6 lib/cyclone_lariat/presenters/graph.rb
cyclone_lariat-1.0.0.rc5 lib/cyclone_lariat/presenters/graph.rb
cyclone_lariat-1.0.0.rc4 lib/cyclone_lariat/presenters/graph.rb
cyclone_lariat-1.0.0.rc3 lib/cyclone_lariat/presenters/graph.rb
cyclone_lariat-1.0.0.rc2 lib/cyclone_lariat/presenters/graph.rb
cyclone_lariat-1.0.0.rc1 lib/cyclone_lariat/presenters/graph.rb