Sha256: 1d39996878f0878973ccc522660bdc1372fa3d19020b4bf041b82c49f259734e

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module Troo
  module Commands
    class ShowComments
      attr_reader :id

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

      # @param  [String]
      # @return [Troo::Commands::ShowComments]
      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

2 entries across 2 versions & 1 rubygems

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