Class: DropboxApi::Metadata::WriteMode
- Defined in:
- lib/dropbox_api/metadata/write_mode.rb
Overview
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:
:add
: Do not overwrite an existing file if there is a conflict. The autorename strategy is to append a number to the file name. For example, "document.txt" might become "document (2).txt".:overwrite
: Always overwrite the existing file. The autorename strategy is the same as it is for add.:update
: Overwrite if the given "rev" matches the existing file's "rev". The autorename strategy is to append the string "conflicted copy" to the file name. For example, "document.txt" might become "document (conflicted copy).txt" or "document (Panda's conflicted copy).txt".
Constant Summary collapse
- VALID_WRITE_MODES =
[ :add, :overwrite, :update ]
Instance Method Summary collapse
- #check_validity ⇒ Object
-
#initialize(write_mode, options = nil) ⇒ WriteMode
constructor
A new instance of WriteMode.
- #to_hash ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(write_mode, options = nil) ⇒ WriteMode
Returns a new instance of WriteMode.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dropbox_api/metadata/write_mode.rb', line 46 def initialize(write_mode, = nil) case write_mode when Hash @write_mode = write_mode when String, ::Symbol @write_mode = { '.tag' => write_mode } @write_mode[write_mode.to_s] = unless .nil? end @write_mode['.tag'] = @write_mode['.tag'].to_sym check_validity end |
Instance Method Details
#check_validity ⇒ Object
61 62 63 64 65 66 67 68 69 |
# 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 ⇒ Object
71 72 73 |
# File 'lib/dropbox_api/metadata/write_mode.rb', line 71 def to_hash @write_mode end |