Sha256: 9681857dd848e5d8c2b4baef55138a8e0aaef0d8a42582da2d218dd2b274d409

Contents?: true

Size: 933 Bytes

Versions: 17

Compression:

Stored size: 933 Bytes

Contents

# frozen_string_literal: true

require "dry/monads"
require "spek"

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

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

          @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 error { message }
            else error { "Unable to handle view action." }
          end
        end

        private

        attr_reader :picker, :viewer

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
gemsmith-19.3.0 lib/gemsmith/cli/actions/view.rb
gemsmith-19.2.0 lib/gemsmith/cli/actions/view.rb
gemsmith-19.1.0 lib/gemsmith/cli/actions/view.rb
gemsmith-19.0.0 lib/gemsmith/cli/actions/view.rb
gemsmith-18.9.0 lib/gemsmith/cli/actions/view.rb
gemsmith-18.8.0 lib/gemsmith/cli/actions/view.rb
gemsmith-18.7.0 lib/gemsmith/cli/actions/view.rb
gemsmith-18.6.0 lib/gemsmith/cli/actions/view.rb
gemsmith-18.5.0 lib/gemsmith/cli/actions/view.rb
gemsmith-18.4.0 lib/gemsmith/cli/actions/view.rb
gemsmith-18.3.0 lib/gemsmith/cli/actions/view.rb
gemsmith-18.2.0 lib/gemsmith/cli/actions/view.rb
gemsmith-18.1.1 lib/gemsmith/cli/actions/view.rb
gemsmith-18.1.0 lib/gemsmith/cli/actions/view.rb
gemsmith-18.0.2 lib/gemsmith/cli/actions/view.rb
gemsmith-18.0.1 lib/gemsmith/cli/actions/view.rb
gemsmith-18.0.0 lib/gemsmith/cli/actions/view.rb