lib/box/item.rb in box-api-0.1.6 vs lib/box/item.rb in box-api-0.1.7

- old
+ new

@@ -9,10 +9,11 @@ @data = Hash.new update_info(info) # merges with the info hash, and renames some fields end + # return the string representation of this item (file or folder) def self.type; raise "Overwrite this method"; end def self.types; type + 's'; end # should be a better way of doing this def type; self.class.type; end @@ -27,10 +28,11 @@ @cached_info = true update_info(get_info) self end + # move the item to the destination folder def move(destination) @api.move(type, id, destination.id) parent.delete_info(self.types) @@ -67,10 +69,11 @@ @parent = nil self end + # set the description of the item def description(message) @api.set_description(type, id, message) self end @@ -100,26 +103,29 @@ protected # sub-classes are meant to implement this def get_info(*args); Hash.new; end + # takes in a hash of info, cleans it, and merges it into the existing info def update_info(info) ninfo = Hash.new - # the api is stupid and some fields are named 'file_id' or 'id' inconsistently, so trim the type off + # some fields are named 'file_id' or 'id' inconsistently, so trim the type off info.each do |name, value| if name.to_s =~ /^#{ type }_(.+)$/; ninfo[$1] = value else; ninfo[name.to_s] = value; end end @data.merge!(ninfo) # merge in the updated info end + # delete the cache for a specific info def delete_info(field) @cached_info = false @data.delete(field) end + # delete the entire cache def clear_info @cached_info = false @data.clear end end