class Locomotive::Wagon::DeleteCommand

Constants

ALL_RESOURCES
SINGLE_RESOURCES
SITE_RESOURCE

Public Class Methods

delete(*args) click to toggle source

@param [ String ] env The environment to delete from @param [ String ] path The path to a wagon site to delete from @param [ String ] resource The resource type to delete. @see RESOURCES @param [ String ] identifier The id or handle of the resource entry to delete

# File lib/locomotive/wagon/commands/delete_command.rb, line 19
def self.delete(*args)
  new(*args).delete
end

Public Instance Methods

delete() click to toggle source

@raise [ ArgumentError ] unless the given resources is in SINGLE_RESOURCES or ALL_RESOURCES

# File lib/locomotive/wagon/commands/delete_command.rb, line 24
def delete
  if resource == SITE_RESOURCE
    delete_site
  elsif SINGLE_RESOURCES.include?(resource)
    delete_single
  elsif ALL_RESOURCES.include?(resource)
    delete_all
  else
    raise ArgumentError, "Resource must be one of #{SINGLE_RESOURCES.join(?,)} if you pass an identifier OR be one of #{ALL_RESOURCES.join(?,)} if you want to delete all the items of that resource."
  end
end

Private Instance Methods

client() click to toggle source
# File lib/locomotive/wagon/commands/delete_command.rb, line 72
def client
  @api_site_client ||= api_site_client(connection_information_from_env_and_path)
end
current_site() click to toggle source
# File lib/locomotive/wagon/commands/delete_command.rb, line 68
def current_site
  @current_site ||= client.current_site
end
delete_all() click to toggle source
# File lib/locomotive/wagon/commands/delete_command.rb, line 54
def delete_all
  client.send(resource_method).destroy_all.tap do |response|
    shell.say "#{response['deletions']} #{resource_method} have been deleted", :green
  end
end
delete_single() click to toggle source
# File lib/locomotive/wagon/commands/delete_command.rb, line 48
def delete_single
  client.send(resource_method).destroy(identifier).tap do |response|
    shell.say "The #{identifier} #{singular_resource_method} has been deleted.", :green
  end
end
delete_site() click to toggle source
# File lib/locomotive/wagon/commands/delete_command.rb, line 38
def delete_site
  if shell.ask('Please, type the handle of your site') == client.options[:handle]
    client.current_site.destroy.tap do |response|
      shell.say "The remote site specified in your #{env} environment has been deleted.", :green
    end
  else
    shell.say 'The delete operation has been cancelled', :red
  end
end
resource_method() click to toggle source
# File lib/locomotive/wagon/commands/delete_command.rb, line 60
def resource_method
  @resource_method ||= resource.pluralize
end
singular_resource_method() click to toggle source
# File lib/locomotive/wagon/commands/delete_command.rb, line 64
def singular_resource_method
  @resource_method.singularize
end