class DropboxApi::Metadata::WriteMode

Your intent when writing a file to some path. This is used to determine what constitutes a conflict and what the autorename strategy is.

In some situations, the conflict behavior is identical:

- If the target path doesn't contain anything, the file is always
  written; no conflict.
- If the target path contains a folder, it's always a conflict.
- If the target path contains a file with identical contents, nothing
  gets written; no conflict.

The conflict checking differs in the case where there's a file at the target path with contents different from the contents you're trying to write. The value will be one of the following datatypes:

Constants

VALID_WRITE_MODES

Public Class Methods

new(write_mode, options = nil) click to toggle source

@example

DropboxApi::Metadata::WriteMode.new :add

@example

DropboxApi::Metadata::WriteMode.new :overwrite

@example

DropboxApi::Metadata::WriteMode.new :update, "a1c10ce0dd78"

@example

DropboxApi::Metadata::WriteMode.new({
  ".tag"=>"update",
  "update"=>"a1c10ce0dd78"
})
# File lib/dropbox_api/metadata/write_mode.rb, line 46
def initialize(write_mode, options = nil)
  case write_mode
  when Hash
    @write_mode = write_mode
  when String, ::Symbol
    @write_mode = {
      '.tag' => write_mode
    }
    @write_mode[write_mode.to_s] = options unless options.nil?
  end
  @write_mode['.tag'] = @write_mode['.tag'].to_sym

  check_validity
end

Public Instance Methods

check_validity() click to toggle source
# File lib/dropbox_api/metadata/write_mode.rb, line 61
def check_validity
  unless valid_mode? @write_mode['.tag']
    raise ArgumentError, "Invalid write mode: #{@write_mode[".tag"]}"
  end

  if @write_mode['.tag'] == :update && @write_mode['update'].nil?
    raise ArgumentError, 'Mode `:update` expects a `rev` number'
  end
end
to_hash() click to toggle source
# File lib/dropbox_api/metadata/write_mode.rb, line 71
def to_hash
  @write_mode
end

Private Instance Methods

valid_mode?(value) click to toggle source
# File lib/dropbox_api/metadata/write_mode.rb, line 77
def valid_mode?(value)
  VALID_WRITE_MODES.include? value
end