Sha256: b030a436454e0b3500d147f83a56265f754904b334a9969a3a4c95b04c6cf5a8

Contents?: true

Size: 926 Bytes

Versions: 5

Compression:

Stored size: 926 Bytes

Contents

# frozen_string_literal: true

require "dry/monads"
require "rubygems/command_manager"

module Gemsmith
  module Tools
    # Pushes a gem package to remote gem server.
    class Pusher
      include Dry::Monads[:result]

      def initialize command: Gem::CommandManager.new, container: Container
        @command = command
        @container = container
      end

      def call specification
        command.run ["push", specification.package_path.to_s, *one_time_password]
        Success specification
      rescue Gem::Exception => error
        Failure error.message
      end

      private

      attr_reader :command, :container

      def one_time_password
        executor.capture3("ykman", "oath", "accounts", "code", "--single", "RubyGems")
                .then { |stdout, _stderr, status| status.success? ? ["--otp", stdout.chomp] : [] }
      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/pusher.rb
gemsmith-17.0.0 lib/gemsmith/tools/pusher.rb
gemsmith-16.2.0 lib/gemsmith/tools/pusher.rb
gemsmith-16.1.0 lib/gemsmith/tools/pusher.rb
gemsmith-16.0.0 lib/gemsmith/tools/pusher.rb