Sha256: 43bd89ec1ec86218760eadfb39b08f1681854b31deff9fea3bfbbcd7beae511f

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require "dry/monads"

module Milestoner
  module Commits
    # Enriches commits and associated trailers for final processing.
    class Enricher
      include Import[:settings]

      include Enrichers::Import[
        :author,
        :body,
        :collaborators,
        :format,
        :issue,
        :milestone,
        :notes,
        :review,
        :signers,
        :uri
      ]

      include Dry::Monads[:result]

      def initialize(categorizer: Commits::Categorizer.new, model: Models::Commit, **)
        @categorizer = categorizer
        @model = model
        super(**)
      end

      def call min: Collector::MIN, max: Collector::MAX
        categorizer.call(min:, max:)
                   .map { |commit| model.for(commit, **build_attributes(commit)) }
                   .then { |commits| Success commits }
      end

      private

      attr_reader :categorizer, :model

      def build_attributes commit
        infused_keys.each.with_object({}) do |key, attributes|
          attributes[key] = __send__(key).call commit
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
milestoner-18.11.0 lib/milestoner/commits/enricher.rb
milestoner-18.10.0 lib/milestoner/commits/enricher.rb
milestoner-18.9.0 lib/milestoner/commits/enricher.rb
milestoner-18.8.0 lib/milestoner/commits/enricher.rb
milestoner-18.7.0 lib/milestoner/commits/enricher.rb
milestoner-18.6.0 lib/milestoner/commits/enricher.rb
milestoner-18.5.0 lib/milestoner/commits/enricher.rb
milestoner-18.4.0 lib/milestoner/commits/enricher.rb