Class: AWS::S3::Tree::ChildCollection

Inherits:
Object
  • Object
show all
Includes:
Core::Model, Enumerable
Defined in:
lib/aws/s3/tree/child_collection.rb

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(parent, collection, options = {}) ⇒ ChildCollection

Returns a new instance of ChildCollection.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Attribute Details

#collectionObjectCollection, ... (readonly)

Returns the collection this tree is based on.

Returns:



48
49
50
# File 'lib/aws/s3/tree/child_collection.rb', line 48

def collection
  @collection
end

#delimiterString (readonly)

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).

Returns:

  • (String)


58
59
60
# File 'lib/aws/s3/tree/child_collection.rb', line 58

def delimiter
  @delimiter
end

#parentTree, BranchNode (readonly)

Returns The parent node in the tree.

Returns:



43
44
45
# File 'lib/aws/s3/tree/child_collection.rb', line 43

def parent
  @parent
end

#prefixString? (readonly)

A tree may have a prefix of where in the bucket to be based from.

Returns:

  • (String, nil)


52
53
54
# File 'lib/aws/s3/tree/child_collection.rb', line 52

def prefix
  @prefix
end

Instance Method Details

#append?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.

Returns:

  • (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.



63
64
65
# File 'lib/aws/s3/tree/child_collection.rb', line 63

def append?
  @append
end

#each {|tree_node| ... } ⇒ nil

Yields up branches and leaves.

A branch node represents a common prefix (like a directory) and a leaf node represents a key (S3 object).

Yields:

  • (tree_node)

    Yields up a mixture of branches and leafs.

Yield Parameters:

Returns:

  • (nil)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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