Sha256: d6f704c8caaf132ee3ca2b9fcbf129ec9ff04482948dc39c71b4d6ed62746bfe

Contents?: true

Size: 906 Bytes

Versions: 2

Compression:

Stored size: 906 Bytes

Contents

module Troo
  module Commands
    class ShowComments
      attr_reader :id

      class << self
        def dispatch(id = nil)
          new(id).render
        end
      end

      def initialize(id = nil)
        @id = id
      end

      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.10 lib/troo/cli/commands/show/show_comments.rb
troo-0.0.9 lib/troo/cli/commands/show/show_comments.rb