class AWS::S3::Tree::ChildCollection

Attributes

collection[R]

@return [ObjectCollection, ObjectVersionCollection,

MultipartUploadCollection] Returns the collection this
tree is based on.
delimiter[R]

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]

parent[R]

@return [Tree, BranchNode] The parent node in the tree.

prefix[R]

A tree may have a prefix of where in the bucket to be based from. @return [String,nil]

Public Class Methods

new(parent, collection, options = {}) click to toggle source

@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

Public Instance Methods

append?() click to toggle source

@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
each() { |leaf_node| ... } click to toggle source

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

Protected Instance Methods

prefix_with_delim() click to toggle source
# 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