Sha256: e8ee0941d5429dd576e7e138342675971bdfe9c8b64821363cc57acb4b256bca

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

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

module Gemsmith
  module CLI
    module Actions
      # Handles the install action.
      class Install < Sod::Action
        include Gemsmith::Import[:logger]
        include Dry::Monads[:result]

        description "Install gem for local development."

        ancillary "Optionally computes gem package based on current directory."

        on %w[-i --install], argument: "[GEM]"

        default { Pathname.pwd.basename }

        def initialize(installer: Tools::Installer.new, loader: Spek::Loader, **)
          super(**)
          @installer = installer
          @loader = loader
        end

        # :reek:ControlParameter
        def call name = nil
          case installer.call loader.call("#{name || default}.gemspec")
            in Success(spec) then logger.info { "Installed: #{spec.package_name}." }
            in Failure(message) then log_error { message }
            else log_error { "Unable to handle install action." }
          end
        end

        private

        attr_reader :installer, :loader

        def log_error(&) = logger.error(&)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gemsmith-20.1.0 lib/gemsmith/cli/actions/install.rb
gemsmith-20.0.0 lib/gemsmith/cli/actions/install.rb