Class: Calligraphy::Move

Inherits:
Copy show all
Defined in:
lib/calligraphy/move.rb

Instance Attribute Summary

Attributes inherited from WebDavRequest

#headers, #resource, #response

Instance Method Summary collapse

Methods inherited from WebDavRequest

#initialize

Constructor Details

This class inherits a constructor from Calligraphy::WebDavRequest

Instance Method Details

#requestObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/calligraphy/move.rb', line 3

def request
  return :locked if @resource.locked_to_user? @headers

  options = copy_move_options

  if @resource.is_true? options[:overwrite]
    to_path = options[:destination].tap { |s| s.slice! @resource.mount_point }
    to_resource = @resource.class.new resource: to_path, req: @request, root_dir: @resource.root_dir

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

  copy_status = super
  return copy_status if [:precondition_failed, :conflict].include? copy_status

  @resource.delete_collection

  if copy_status == :created && to_resource_existed
    return :no_content
  else
    response.headers['Location'] = options[:destination] if copy_status == :created
    return copy_status
  end
end