Sha256: af04201f6e187d7d18cade576a386209a0ea6d6046d5509a91816a9731c1f5fb

Contents?: true

Size: 873 Bytes

Versions: 1

Compression:

Stored size: 873 Bytes

Contents

module Troo
  module Commands
    class Default
      class << self
        # @param  []
        # @param  []
        # @return [String]
        def dispatch(klass, id)
          new(klass, id).set_default
        end
      end

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

      # @return [String]
      def set_default
        return success if resource && resource.set_default!
        error
      end

      private

      attr_reader :id, :klass

      def success
        "'#{name}' set as default."
      end

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

      def type
        klass.type.to_s.capitalize
      end

      def name
        resource.decorator.name
      end

      def resource
        @resource ||= klass.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/default.rb