class Dbox::DB::DropboxBlob

Attributes

modified_at[R]
path[R]
revision[R]

Public Class Methods

new(db, res) click to toggle source
# File lib/dbox/db.rb, line 165
def initialize(db, res)
  @db = db
  @path = @db.remote_to_relative_path(res["path"])
  update_modification_info(res)
end

Public Instance Methods

api() click to toggle source
# File lib/dbox/db.rb, line 282
def api
  @db.api
end
create(direction) click to toggle source
# File lib/dbox/db.rb, line 204
def create(direction)
  case direction
  when :down
    create_local
  when :up
    create_remote
  end
end
create_local() click to toggle source
# File lib/dbox/db.rb, line 231
def create_local; raise RuntimeError, "Not implemented"; end
create_remote() click to toggle source
# File lib/dbox/db.rb, line 235
def create_remote; raise RuntimeError, "Not implemented"; end
delete(direction) click to toggle source
# File lib/dbox/db.rb, line 222
def delete(direction)
  case direction
  when :down
    delete_local
  when :up
    delete_remote
  end
end
delete_local() click to toggle source
# File lib/dbox/db.rb, line 232
def delete_local; raise RuntimeError, "Not implemented"; end
delete_remote() click to toggle source
# File lib/dbox/db.rb, line 236
def delete_remote; raise RuntimeError, "Not implemented"; end
dir?() click to toggle source
# File lib/dbox/db.rb, line 200
def dir?
  raise RuntimeError, "Not implemented"
end
force_metadata_update_from_server() click to toggle source

this downloads the metadata about this blob from the server and overwrites the metadata & timestamp IMPORTANT: should only be called if you are CERTAIN the file is up to date

# File lib/dbox/db.rb, line 271
def force_metadata_update_from_server
  res = api.metadata(remote_path)
  update_modification_info(res)
  update_file_timestamp
end
local_path() click to toggle source
# File lib/dbox/db.rb, line 192
def local_path
  @db.relative_to_local_path(@path)
end
modified?(res) click to toggle source
# File lib/dbox/db.rb, line 239
def modified?(res)
  out = !(@revision == res["revision"] && time_to_s(@modified_at) == time_to_s(res["modified"]))
  log.debug "#{path} modified? => #{out}"
  out
end
parse_time(t) click to toggle source
# File lib/dbox/db.rb, line 255
def parse_time(t)
  case t
  when Time
    t
  when String
    Time.parse(t)
  end
end
remote_path() click to toggle source
# File lib/dbox/db.rb, line 196
def remote_path
  @db.relative_to_remote_path(@path)
end
saving_parent_timestamp(&proc) click to toggle source
# File lib/dbox/db.rb, line 277
def saving_parent_timestamp(&proc)
  parent = File.dirname(local_path)
  DB.saving_timestamp(parent, &proc)
end
smart_new(res) click to toggle source
# File lib/dbox/db.rb, line 184
def smart_new(res)
  if res["is_dir"]
    DropboxDir.new(@db, res)
  else
    DropboxFile.new(@db, res)
  end
end
time_to_s(t) click to toggle source
# File lib/dbox/db.rb, line 245
def time_to_s(t)
  case t
  when Time
    # matches dropbox time format
    t.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
  when String
    t
  end
end
update(direction) click to toggle source
# File lib/dbox/db.rb, line 213
def update(direction)
  case direction
  when :down
    update_local
  when :up
    update_remote
  end
end
update_file_timestamp() click to toggle source
# File lib/dbox/db.rb, line 264
def update_file_timestamp
  File.utime(Time.now, @modified_at, local_path)
end
update_local() click to toggle source
# File lib/dbox/db.rb, line 233
def update_local; raise RuntimeError, "Not implemented"; end
update_modification_info(res) click to toggle source
# File lib/dbox/db.rb, line 171
def update_modification_info(res)
  raise(BadPath, "Bad path (#{remote_path} != #{res["path"]})") unless remote_path == res["path"]
  raise(RuntimeError, "Mode on #{@path} changed between file and dir -- not supported yet") unless dir? == res["is_dir"]
  last_modified_at = @modified_at
  @modified_at = parse_time(res["modified"])
  if res["revision"]
    @revision = res["revision"]
  else
    @revision = -1 if @modified_at != last_modified_at
  end
  log.debug "updated modification info on #{path.inspect}: r#{@revision}, #{@modified_at}"
end
update_remote() click to toggle source
# File lib/dbox/db.rb, line 237
def update_remote; raise RuntimeError, "Not implemented"; end