Sha256: aab4bfd5386d88cfe4033a93519d775795bf836ad84e4c88f63491726d392792

Contents?: true

Size: 906 Bytes

Versions: 5

Compression:

Stored size: 906 Bytes

Contents

# frozen_string_literal: true

require "dry/monads"

module Gemsmith
  module Tools
    # Installs a locally built gem.
    class Installer
      include Dry::Monads[:result, :do]

      # Order matters.
      STEPS = [Tools::Cleaner.new, Tools::Packager.new].freeze

      def initialize steps: STEPS, container: Container
        @steps = steps
        @container = container
      end

      def call specification
        steps.each { |step| yield step.call(specification) }
        run specification
      end

      private

      attr_reader :steps, :container

      def run specification
        path = specification.package_path

        executor.capture3("gem", "install", path.to_s).then do |_stdout, _stderr, status|
          status.success? ? Success(specification) : Failure("Unable to install: #{path}.")
        end
      end

      def executor = container[__method__]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gemsmith-17.0.1 lib/gemsmith/tools/installer.rb
gemsmith-17.0.0 lib/gemsmith/tools/installer.rb
gemsmith-16.2.0 lib/gemsmith/tools/installer.rb
gemsmith-16.1.0 lib/gemsmith/tools/installer.rb
gemsmith-16.0.0 lib/gemsmith/tools/installer.rb