class Troo::Commands::Refresh

Attributes

id[R]
klass[R]

Public Class Methods

dispatch(klass, id = nil) click to toggle source

@param [] @param [, NilClass] @return [String]

# File lib/troo/cli/commands/refresh.rb, line 10
def dispatch(klass, id = nil)
  new(klass, id).refresh
end
new(klass, id = nil) click to toggle source

@param [] @param [, NilClass] @return [Troo::Commands::Refresh]

# File lib/troo/cli/commands/refresh.rb, line 18
def initialize(klass, id = nil)
  @klass, @id = klass, id
end

Public Instance Methods

refresh() click to toggle source

@return [String]

# File lib/troo/cli/commands/refresh.rb, line 23
def refresh
  return not_found    if not_found?
  return many_success if multiple_refreshed?
  success
end

Private Instance Methods

error() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 54
def error
  "#{type.capitalize} cannot be found."
end
local() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 81
def local
  @local ||= Retrieval::Local
    .retrieve(klass, id, allow_remote: false)
end
many_success() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 33
def many_success
  "Multiple #{type}s refreshed."
end
multiple_refreshed?() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 37
def multiple_refreshed?
  resource.count > 1
end
no_default() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 58
def no_default
  "Specify an <id> or use 'troo default #{type} <id>' " \
  "to set a default #{type} first."
end
not_found() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 45
def not_found
  return [error, no_default].join(' ') unless id
  error
end
not_found?() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 50
def not_found?
  resource.nil? || resource.none?
end
remote() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 76
def remote
  @remote ||= Retrieval::Remote
    .fetch(klass.remote, local.external_id)
end
resource() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 71
def resource
  return [] unless local
  remote
end
resource_name() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 67
def resource_name
  resource.first.decorator.name
end
success() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 41
def success
  "'#{resource_name}' refreshed."
end
type() click to toggle source
# File lib/troo/cli/commands/refresh.rb, line 63
def type
  klass.type.to_s
end