Sha256: bb4f94fcb092f2e6164397a0f9ede73fcf547362d27b1d49283bd7aefa844cb7

Contents?: true

Size: 889 Bytes

Versions: 1

Compression:

Stored size: 889 Bytes

Contents

# frozen_string_literal: true

require "dry/monads"
require "pathname"
require "spek"

module Milestoner
  module Configuration
    module Transformers
      module Gems
        # Conditionally updates project URI based on specification home page URL.
        class URI
          include Import[:spec_loader]
          include Dry::Monads[:result]

          def initialize(key = :project_uri, path: "#{Pathname.pwd.basename}.gemspec", **)
            @key = key
            @path = path
            super(**)
          end

          def call(content) = Success process(content)

          private

          attr_reader :key, :path

          def process content
            content.fetch(key) { spec_loader.call(path).homepage_url }
                   .then { |value| String(value).empty? ? content : content.merge!(key => value) }
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
milestoner-17.0.0 lib/milestoner/configuration/transformers/gems/uri.rb