class Calligraphy::Move

Responsible for copying a resource then deleting the original source.

Public Instance Methods

execute() click to toggle source

Executes the WebDAV request for a particular resource.

Calls superclass method Calligraphy::Copy#execute
# File lib/calligraphy/web_dav_request/move.rb, line 7
def execute
  return :locked if @resource.locked_to_user? @headers

  if @resource.true? options[:overwrite]
    previous_resource_existed = overwrite_destination
  end

  status = super
  return status if %i[precondition_failed conflict].include? status

  @resource.delete_collection

  response_status status, previous_resource_existed
end

Private Instance Methods

destination_resource(to_path) click to toggle source
# File lib/calligraphy/web_dav_request/move.rb, line 40
def destination_resource(to_path)
  @resource.class.new(
    resource: to_path,
    req: @request,
    root_dir: @resource.root_dir
  )
end
options() click to toggle source
# File lib/calligraphy/web_dav_request/move.rb, line 24
def options
  copy_move_options
end
overwrite_destination() click to toggle source
# File lib/calligraphy/web_dav_request/move.rb, line 28
def overwrite_destination
  to_path = options[:destination].tap { |s| s.slice! @resource.mount_point }
  to_resource = destination_resource to_path

  if to_resource.exists?
    to_resource.delete_collection
    previous_resource_existed = true
  end

  previous_resource_existed
end
response_status(status, previous_resource) click to toggle source
# File lib/calligraphy/web_dav_request/move.rb, line 48
def response_status(status, previous_resource)
  return :no_content if status == :created && previous_resource

  response.headers['Location'] = options[:destination] if status == :created

  status
end