You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Module: AWS::S3::PrefixedCollection

Defined in:
lib/aws/s3/prefixed_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core::Collection

#each, #each_batch, #enum, #first, #in_groups_of, #page

Instance Attribute Details

#prefixString? (readonly)

Returns The prefix of this collection.

Returns:

  • (String, nil)

    The prefix of this collection.



30
31
32
# File 'lib/aws/s3/prefixed_collection.rb', line 30

def prefix
  @prefix
end

Instance Method Details

#with_prefix(prefix, mode = :replace) ⇒ Collection

Returns a new collection with a different prefix

Examples:


objects = collection.with_prefix('photos')
objects.prefix #=> 'photos'

Chaining with_prefix replaces previous prefix


objects = collection.with_prefix('photos').with_prefix('videos')
objects.prefix #=> 'videos'

Chaining with_prefix with :append


objects = collection.with_prefix('a/').with_prefix('b/', :append)
objects.prefix #=> 'a/b/'

Chaining with_prefix with :prepend


objects = collection.with_prefix('a/').with_prefix('b/', :prepend)
objects.prefix #=> 'b/a/'

Parameters:

  • prefix (String)

    The prefix condition that limits what objects are returned by this collection.

  • mode (Symbol) (defaults to: :replace)

    (:replace) If you chain calls to #with_prefix the mode affects if the prefix prepends, appends, or replaces. Valid modes are: * :replace * :append * :prepend

Returns:

  • (Collection)

    Returns a new collection with a modified prefix.



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/aws/s3/prefixed_collection.rb', line 63

def with_prefix prefix, mode = :replace
  new_prefix = case mode
  when :replace then prefix
  when :append  then "#{@prefix}#{prefix}"
  when :prepend then "#{prefix}#{@prefix}"
  else
    raise ArgumentError, "invalid prefix mode `#{mode}`, it must be " +
      ":replace, :append or :prepend"
  end
  self.class.new(bucket, :prefix => new_prefix)
end