Sha256: 7f5ec1270f588db2fe2767d864dd0733937057e86ef01ee2588532f101ce89cb
Contents?: true
Size: 1.64 KB
Versions: 2
Compression:
Stored size: 1.64 KB
Contents
module Troo module Commands class Refresh attr_reader :id class << self # @param [] # @param [, NilClass] # @return [String] def dispatch(klass, id = nil) new(klass, id).refresh end end # @param [] # @param [, NilClass] # @return [Troo::Commands::Refresh] def initialize(klass, id = nil) @klass, @id = klass, id end # @return [String] def refresh return not_found if not_found? return many_success if multiple_refreshed? success end private attr_reader :klass def many_success "Multiple #{type}s refreshed." end def multiple_refreshed? resource.count > 1 end def success "'#{resource_name}' refreshed." end def not_found return [error, no_default].join(' ') unless id error end def not_found? resource.nil? || resource.none? end def error "#{type.capitalize} cannot be found." end def no_default "Specify an <id> or use 'troo default #{type} <id>' " \ "to set a default #{type} first." end def type klass.type.to_s end def resource_name resource.first.decorator.name end def resource return [] unless local remote end def remote @remote ||= Retrieval::Remote .fetch(klass.remote, local.external_id) end def local @local ||= Retrieval::Local .retrieve(klass, id, allow_remote: false) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
troo-0.0.15 | lib/troo/cli/commands/refresh.rb |
troo-0.0.14 | lib/troo/cli/commands/refresh.rb |