Sha256: b24b7b66fb0ac467bfb50cf60957b05d21fbd78480bef1cb29ba960980d41c4b

Contents?: true

Size: 954 Bytes

Versions: 1

Compression:

Stored size: 954 Bytes

Contents

# frozen_string_literal: true

require "dry/monads"

module Gemsmith
  module CLI
    module Actions
      # Handles the edit action for editing an installed gem.
      class Edit
        include Dry::Monads[:result]

        def initialize picker: Gems::Picker, editor: Tools::Editor.new, container: Container
          @picker = picker
          @editor = editor
          @container = container
        end

        def call gem_name
          case picker.call(gem_name).bind { |spec| editor.call spec }
            in Success(spec) then logger.info { "Editing: #{spec.named_version}." }
            in Failure(message) then error { message }
            else error { "Unable to handle edit action." }
          end
        end

        private

        attr_reader :picker, :editor, :container

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

        def kernel = container[__method__]

        def logger = container[__method__]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gemsmith-16.0.0 lib/gemsmith/cli/actions/edit.rb