Sha256: f7a615fae6ff6df50c4c991a82f42e57027d27d0ce935517daa810220b7d9671

Contents?: true

Size: 1 KB

Versions: 18

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

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

module Gemsmith
  module CLI
    module Actions
      # Handles the edit action for editing an installed gem.
      class Edit < Sod::Action
        include Import[:kernel, :logger]
        include Dry::Monads[:result]

        description "Edit installed gem in default editor."

        on %w[-e --edit], argument: "GEM"

        def initialize(picker: Spek::Picker, editor: Tools::Editor.new, **)
          super(**)
          @picker = picker
          @editor = editor
        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 log_error { message }
            else log_error { "Unable to handle edit action." }
          end
        end

        private

        attr_reader :picker, :editor

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
gemsmith-21.10.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-21.9.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-21.6.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-21.5.1 lib/gemsmith/cli/actions/edit.rb
gemsmith-21.5.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-21.4.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-21.3.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-21.2.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-21.1.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-21.0.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-20.7.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-20.6.1 lib/gemsmith/cli/actions/edit.rb
gemsmith-20.6.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-20.5.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-20.4.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-20.3.0 lib/gemsmith/cli/actions/edit.rb
gemsmith-20.2.1 lib/gemsmith/cli/actions/edit.rb
gemsmith-20.2.0 lib/gemsmith/cli/actions/edit.rb