Sha256: eadf8052a9fb69531a22f233ea0738bb02629e97ad6df9e1b758d842ddfca725

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 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 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

        def call name = default
          case installer.call loader.call("#{name}.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

10 entries across 10 versions & 1 rubygems

Version Path
gemsmith-22.10.0 lib/gemsmith/cli/actions/install.rb
gemsmith-22.9.0 lib/gemsmith/cli/actions/install.rb
gemsmith-22.8.0 lib/gemsmith/cli/actions/install.rb
gemsmith-22.7.0 lib/gemsmith/cli/actions/install.rb
gemsmith-22.6.0 lib/gemsmith/cli/actions/install.rb
gemsmith-22.5.0 lib/gemsmith/cli/actions/install.rb
gemsmith-22.4.0 lib/gemsmith/cli/actions/install.rb
gemsmith-22.3.0 lib/gemsmith/cli/actions/install.rb
gemsmith-22.2.0 lib/gemsmith/cli/actions/install.rb
gemsmith-20.2.0 lib/gemsmith/cli/actions/install.rb