Sha256: c0ab0eac681cb78ea5b425f41524e567f4f596a657c7036df1d4dfa6e11c62ef

Contents?: true

Size: 896 Bytes

Versions: 2

Compression:

Stored size: 896 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 [Troo::Commands::Default]
      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

2 entries across 2 versions & 1 rubygems

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