lib/box/item.rb in box-api-0.1.9 vs lib/box/item.rb in box-api-0.2.0
- old
+ new
@@ -1,5 +1,7 @@
+require 'box/comment'
+
module Box
# Represents a folder or file stored on Box. Any attributes or actions
# typical to a Box item can be accessed through this class. The {Item}
# class contains only methods shared by {Folder} and {File}, and should
# not be instanciated directly.
@@ -117,17 +119,17 @@
# Set the description of this item.
#
# @param [String] message The description message to use.
# @return [Item] self
- def description(message)
+ def set_description(message)
@api.set_description(type, id, message)
self
end
- # @return [String] The path of this item. This starts with a '/'.
+ # @return [String] The path of this item. This starts with a '/', unless it is root.
def path
"#{ parent.path + '/' if parent }#{ name }"
end
# Provides an easy way to access this item's info.
@@ -137,21 +139,35 @@
def method_missing(sym, *args, &block)
# TODO: Why not symbols?
# convert to a string
str = sym.to_s
+ # determine whether to refresh the cache
+ refresh = args ? args.first : false
+
# return the value if it already exists
- return @data[str] if @data.key?(str)
+ return @data[str] if not refresh and @data.key?(str)
# value didn't exist, so try to update the info
- self.info
+ # TODO: Figure out a good way to work with multiple sources.
+ case str
+ when 'comments'
+ self.get_comments
+ when
+ self.info(refresh)
+ end
# try returning the value again
return @data[str] if @data.key?(str)
# we didn't find a value, so it must be invalid
# call the normal method_missing function
super
+ end
+
+ # Handles some cases in method_missing, but won't always be accurate.
+ def respond_to?(sym)
+ @data.key?(sym.to_s) or super
end
# Consider the item cached. This prevents an additional api
# when we know the item is fully fetched.
def force_cached_info