Class: Dbox::DB::DropboxBlob
- Inherits:
-
Object
- Object
- Dbox::DB::DropboxBlob
- Includes:
- Loggable
- Defined in:
- lib/dbox/db.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#modified_at ⇒ Object
readonly
Returns the value of attribute modified_at.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
Instance Method Summary collapse
- #api ⇒ Object
- #create(direction) ⇒ Object
- #create_local ⇒ Object
- #create_remote ⇒ Object
- #delete(direction) ⇒ Object
- #delete_local ⇒ Object
- #delete_remote ⇒ Object
- #dir? ⇒ Boolean
-
#force_metadata_update_from_server ⇒ Object
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.
-
#initialize(db, res) ⇒ DropboxBlob
constructor
A new instance of DropboxBlob.
- #local_path ⇒ Object
- #modified?(res) ⇒ Boolean
- #parse_time(t) ⇒ Object
- #remote_path ⇒ Object
- #saving_parent_timestamp(&proc) ⇒ Object
- #smart_new(res) ⇒ Object
- #time_to_s(t) ⇒ Object
- #update(direction) ⇒ Object
- #update_file_timestamp ⇒ Object
- #update_local ⇒ Object
- #update_modification_info(res) ⇒ Object
- #update_remote ⇒ Object
Methods included from Loggable
Constructor Details
#initialize(db, res) ⇒ DropboxBlob
Returns a new instance of DropboxBlob.
165 166 167 168 169 |
# 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 |
Instance Attribute Details
#modified_at ⇒ Object (readonly)
Returns the value of attribute modified_at.
163 164 165 |
# File 'lib/dbox/db.rb', line 163 def modified_at @modified_at end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
163 164 165 |
# File 'lib/dbox/db.rb', line 163 def path @path end |
#revision ⇒ Object (readonly)
Returns the value of attribute revision.
163 164 165 |
# File 'lib/dbox/db.rb', line 163 def revision @revision end |
Instance Method Details
#api ⇒ Object
282 283 284 |
# File 'lib/dbox/db.rb', line 282 def api @db.api end |
#create(direction) ⇒ Object
204 205 206 207 208 209 210 211 |
# File 'lib/dbox/db.rb', line 204 def create(direction) case direction when :down create_local when :up create_remote end end |
#create_local ⇒ Object
231 |
# File 'lib/dbox/db.rb', line 231 def create_local; raise RuntimeError, "Not implemented"; end |
#create_remote ⇒ Object
235 |
# File 'lib/dbox/db.rb', line 235 def create_remote; raise RuntimeError, "Not implemented"; end |
#delete(direction) ⇒ Object
222 223 224 225 226 227 228 229 |
# File 'lib/dbox/db.rb', line 222 def delete(direction) case direction when :down delete_local when :up delete_remote end end |
#delete_local ⇒ Object
232 |
# File 'lib/dbox/db.rb', line 232 def delete_local; raise RuntimeError, "Not implemented"; end |
#delete_remote ⇒ Object
236 |
# File 'lib/dbox/db.rb', line 236 def delete_remote; raise RuntimeError, "Not implemented"; end |
#dir? ⇒ Boolean
200 201 202 |
# File 'lib/dbox/db.rb', line 200 def dir? raise RuntimeError, "Not implemented" end |
#force_metadata_update_from_server ⇒ Object
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
271 272 273 274 275 |
# File 'lib/dbox/db.rb', line 271 def res = api.(remote_path) update_modification_info(res) end |
#local_path ⇒ Object
192 193 194 |
# File 'lib/dbox/db.rb', line 192 def local_path @db.relative_to_local_path(@path) end |
#modified?(res) ⇒ Boolean
239 240 241 242 243 |
# 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) ⇒ Object
255 256 257 258 259 260 261 262 |
# 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 ⇒ Object
196 197 198 |
# File 'lib/dbox/db.rb', line 196 def remote_path @db.relative_to_remote_path(@path) end |
#saving_parent_timestamp(&proc) ⇒ Object
277 278 279 280 |
# File 'lib/dbox/db.rb', line 277 def (&proc) parent = File.dirname(local_path) DB.(parent, &proc) end |
#smart_new(res) ⇒ Object
184 185 186 187 188 189 190 |
# 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) ⇒ Object
245 246 247 248 249 250 251 252 253 |
# 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) ⇒ Object
213 214 215 216 217 218 219 220 |
# 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 ⇒ Object
264 265 266 |
# File 'lib/dbox/db.rb', line 264 def File.utime(Time.now, @modified_at, local_path) end |
#update_local ⇒ Object
233 |
# File 'lib/dbox/db.rb', line 233 def update_local; raise RuntimeError, "Not implemented"; end |
#update_modification_info(res) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 |
# 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 ⇒ Object
237 |
# File 'lib/dbox/db.rb', line 237 def update_remote; raise RuntimeError, "Not implemented"; end |