class Calligraphy::Copy

Responsible for creating a duplicate of the source resource identified by the request to the destination resource identified by the URI in the Destination header.

Public Instance Methods

execute() click to toggle source

Executes the WebDAV request for a particular resource.

# File lib/calligraphy/web_dav_request/copy.rb, line 9
def execute
  options = copy_move_options
  copy_options = @resource.copy_options options

  unless copy_options[:can_copy]
    return :precondition_failed if copy_options[:ancestor_exist]
    return :conflict
  end

  return :locked if copy_options[:locked]

  overwritten = @resource.copy options
  overwritten ? :no_content : :created
end

Private Instance Methods

copy_move_options() click to toggle source
# File lib/calligraphy/web_dav_request/copy.rb, line 26
def copy_move_options
  {
    depth: @headers['Depth'],
    destination: remove_trailing_slash(destination_header),
    overwrite: @headers['Overwrite'] || true
  }
end
destination_header() click to toggle source
# File lib/calligraphy/web_dav_request/copy.rb, line 34
def destination_header
  @headers['Destination'].split(@headers['Host'])[-1]
end
remove_trailing_slash(input) click to toggle source
# File lib/calligraphy/web_dav_request/copy.rb, line 38
def remove_trailing_slash(input)
  input[-1] == '/' ? input[0..-2] : input
end