@return [ObjectCollection, ObjectVersionCollection,
MultipartUploadCollection] Returns the collection this tree is based on.
When looking at S3 keys as a tree, the delimiter defines what string pattern seperates each level of the tree. The delimiter defaults to ‘/’ (like in a file system). @return [String]
@return [Tree, BranchNode] The parent node in the tree.
A tree may have a prefix of where in the bucket to be based from. @return [String,nil]
@private
# File lib/aws/s3/tree/child_collection.rb, line 24 def initialize parent, collection, options = {} options = { :prefix => nil, :delimiter => '/', :append => true, }.merge(options) @parent = parent @collection = collection @prefix = options[:prefix] @delimiter = options[:delimiter] @append = options[:append] super end
@return [Boolean] Returns true if the tree is set to auto-append
the delimiter to the prefix when the prefix does not end with the delimiter.
# File lib/aws/s3/tree/child_collection.rb, line 63 def append? @append end
Yields up branches and leaves.
A branch node represents a common prefix (like a directory) and a leaf node represents a key (S3 object).
@yield [tree_node] Yields up a mixture of branches and leafs. @yieldparam [BranchNode,LeafNode] tree_node A branch or a leaf. @return [nil]
# File lib/aws/s3/tree/child_collection.rb, line 75 def each &block collection = self.collection if prefix = prefix_with_delim collection = collection.with_prefix(prefix) end collection.each(:delimiter => delimiter) do |member| case when member.respond_to?(:key) yield LeafNode.new(parent, member) when member.respond_to?(:prefix) yield BranchNode.new(parent, member, :delimiter => delimiter, :append => append?) end end nil end
# File lib/aws/s3/tree/child_collection.rb, line 94 def prefix_with_delim return prefix unless append? return nil if prefix.nil? prefix =~ %r#{delimiter}$/ ? prefix : "#{prefix}#{delimiter}" end