Sha256: 944dd715d98b97c7cc7b865cada3d19f1edcc4a97e3645001c25cfb8580a23b4

Contents?: true

Size: 1017 Bytes

Versions: 1

Compression:

Stored size: 1017 Bytes

Contents

module Troo
  module Commands
    class ShowComments
      attr_reader :id

      class << self
        # @param  []
        # @return [String]
        def dispatch(id = nil)
          new(id).render
        end
      end

      # @param  []
      # @return []
      def initialize(id = nil)
        @id = id
      end

      # @return [String]
      def render
        if resource
          presenter
        elsif no_default?
          [error, no_default].join(' ')
        else
          error
        end
      end

      private

      def presenter
        resource.comment_presenter.show
      end

      def error
        "#{type.capitalize} cannot be found."
      end

      def no_default?
        id.nil? && resource.nil?
      end

      def no_default
        "Specify an <id> or use 'troo default #{type} <id>' " \
        "to set a default #{type} first."
      end

      def type
        'card'
      end

      def resource
        @resource ||= Troo::Card.retrieve(id)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
troo-0.0.13 lib/troo/cli/commands/show/show_comments.rb