Sha256: 89f74eb6a0885fd83709b20671fe2fc0b1e15430c5124bcbb790bd2f5e937c8f

Contents?: true

Size: 1.14 KB

Versions: 9

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

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

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

        description "Publish gem to remote gem server."

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

        on %w[-p --publish], argument: "[GEM]"

        default { Pathname.pwd.basename }

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

        def call name = default
          case publisher.call loader.call("#{name}.gemspec")
            in Success(spec) then logger.info { "Published: #{spec.package_name}." }
            in Failure(message) then log_error message
            else log_error "Publish failed, unable to parse result."
          end
        end

        private

        attr_reader :publisher, :loader

        def log_error(message) = logger.error { message }
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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