Sha256: 1a91823ae2fbc877187e054db77db1c64b76c43581b4e05aabf139c2aeb0bf94

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

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

module Gemsmith
  module CLI
    module Actions
      # Handles the view action for viewing an installed gem in default browser.
      class View < Sod::Action
        include Import[:logger]
        include Dry::Monads[:result]

        description "View installed gem in default browser."

        on %w[-V --view], argument: "GEM"

        def initialize(picker: Spek::Picker, viewer: Tools::Viewer.new, **)
          super(**)
          @picker = picker
          @viewer = viewer
        end

        def call gem_name
          case picker.call(gem_name).bind { |spec| viewer.call spec }
            in Success(spec) then logger.info { "Viewing: #{spec.named_version}." }
            in Failure(message) then log_error { message }
            else log_error { "Unable to handle view action." }
          end
        end

        private

        attr_reader :picker, :viewer

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

Version data entries

11 entries across 11 versions & 1 rubygems

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