Sha256: ce44e27a458b702a3954518275640de9457820594b9b1dfb3843a669e9d9dce0

Contents?: true

Size: 1.62 KB

Versions: 96

Compression:

Stored size: 1.62 KB

Contents

require 'pact/doc/markdown/interaction_renderer'
require 'pact/doc/sort_interactions'

module Pact
  module Doc
    module Markdown
      class ConsumerContractRenderer

        def initialize consumer_contract
          @consumer_contract = consumer_contract
        end

        def self.call consumer_contract
          new(consumer_contract).call
        end

        def call
          title + summaries_title + summaries.join + interactions_title + full_interactions.join
        end

        private

        attr_reader :consumer_contract

        def title
          "### A pact between #{consumer_name} and #{provider_name}\n\n"
        end

        def interaction_renderers
          @interaction_renderers ||= sorted_interactions.collect{|interaction| InteractionRenderer.new interaction, @consumer_contract}
        end

        def summaries_title
          "#### Requests from #{consumer_name} to #{provider_name}\n\n"
        end

        def interactions_title
          "#### Interactions\n\n"
        end

        def summaries
          interaction_renderers.collect(&:render_summary)
        end

        def full_interactions
          interaction_renderers.collect(&:render_full_interaction)
        end

        def sorted_interactions
          SortInteractions.call(consumer_contract.interactions)
        end

        def consumer_name
          markdown_escape consumer_contract.consumer.name
        end

        def provider_name
          markdown_escape consumer_contract.provider.name
        end

        def markdown_escape string
          string.gsub('*','\*').gsub('_','\_')
        end

      end
    end
  end
end

Version data entries

96 entries across 96 versions & 1 rubygems

Version Path
pact-1.65.3 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.65.2 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.65.1 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.65.0 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.64.0 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.63.0 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.62.0 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.61.0 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.60.0 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.59.0 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.58.0 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.57.0 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.56.0 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.55.7 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.55.6 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.55.5 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.55.4 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.55.3 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.55.2 lib/pact/doc/markdown/consumer_contract_renderer.rb
pact-1.55.1 lib/pact/doc/markdown/consumer_contract_renderer.rb