Sha256: 838b73a5f5afc30052b1077264720c79b9d837ed08ba95ba3e390da096bc90e3

Contents?: true

Size: 934 Bytes

Versions: 2

Compression:

Stored size: 934 Bytes

Contents

# frozen_string_literal: true

module Milestoner
  module Builders
    # Builds I/O stream output.
    class Stream
      include Milestoner::Import[:settings, :logger, :io]

      def initialize(tagger: Commits::Tagger.new, view: Views::Milestones::Show.new, **)
        @tagger = tagger
        @view = view
        super(**)
      end

      def call
        tagger.call
              .fmap { |tags| write tags }
              .alt_map { |message| failure message }
      end

      private

      attr_reader :tagger, :view

      def write(tags) = build(tags).tap { |content| io.write content }

      def build tags
        tags.reduce([]) { |content, tag| content.append render(tag) }
            .join(%(\n#{"-" * 80}\n\n))
      end

      def render(tag) = view.call tag:, layout: settings.build_layout, format: :stream

      def failure message
        logger.error { message }
        message
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
milestoner-18.12.0 lib/milestoner/builders/stream.rb
milestoner-18.11.0 lib/milestoner/builders/stream.rb