Sha256: 5ec06d01ff9a7dd0698661c07fccb662ae1c3f2a438f15c09fad48f7f2659936

Contents?: true

Size: 1.02 KB

Versions: 18

Compression:

Stored size: 1.02 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[:kernel, :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

18 entries across 18 versions & 1 rubygems

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