Method: CloudFS::Item#restore

Defined in:
lib/cloudfs/item.rb

#restore(destination, method: 'FAIL', restore_argument: nil, raise_exception: false) ⇒ Boolean

Note:

This item's properties are updated if successful

Note:

exist: 'RECREATE' with named path is expensive operation as items in named path hierarchy are traversed in order to fetch Restored item's properties.

Restore this item from trash

Examples:

item.restore
item.restore("/FOPqySw3ToK_25y-gagUfg", exists: 'RESCUE')
item.restore(folderobj, exists: 'RESCUE')
item.restore("/depth1/depth2", exists: 'RECREATE')

Parameters:

  • destination (Folder, String)

    ('RESCUE' (default root), RECREATE(named path)) destination folder path depending on exists option to place item into if the original path does not exist.

  • method (String) (defaults to: 'FAIL')

    ('FAIL', 'RESCUE', 'RECREATE') action to take if the recovery operation encounters issues, default 'FAIL'

  • raise_exception (Boolean) (defaults to: false)

    (false) method suppresses exceptions and returns false if set to false, added so that consuming application can control behaviour

  • restore_argument (String) (defaults to: nil)

    update this item after it has been restored

Returns:

  • (Boolean)

    true/false

Raises:



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/cloudfs/item.rb', line 473

def restore(destination, method: 'FAIL', restore_argument: nil, raise_exception: false) # restore argument.
  fail RestAdapter::Errors::OperationNotAllowedError,
       'Item needs to be in trash for Restore operation' unless @in_trash
  FileSystemCommon.validate_item_state(destination)

  destination_url = FileSystemCommon.get_folder_url(destination)
  @rest_adapter.recover_trash_item(
      @url,
      destination: destination_url,
      restore: method)

  if restore_argument
    set_restored_item_properties(destination_url, method)
  end

  true
rescue RestAdapter::Errors::SessionNotLinked, RestAdapter::Errors::ServiceError,
    RestAdapter::Errors::ArgumentError, RestAdapter::Errors::InvalidItemError,
    RestAdapter::Errors::OperationNotAllowedError
  raise $! if raise_exception
  false
end