class AWS::S3::BucketTagCollection
Manages tags for a single S3
{Bucket}.
@example Setting a tag.
bucket.tags['key'] = 'value'
@example Getting a tag.
bucket.tags['key'] #=> 'value'
@example Getting all tags
bucket.tags.to_h #=> { 'key' => 'value', ... }
@example Removing all tags
bucket.tags.clear
Attributes
bucket[R]
@return [Bucket]
Public Class Methods
new(bucket, options = {})
click to toggle source
@param [Bucket] bucket @param [Hash] options
Calls superclass method
AWS::Core::Model::new
# File lib/aws/s3/bucket_tag_collection.rb, line 43 def initialize bucket, options = {} @bucket = bucket super end
Public Instance Methods
[](key)
click to toggle source
@param [String] key @return [String,nil] Returns the tag for the given key. If there
Returns `nil` if the key does not exist.
# File lib/aws/s3/bucket_tag_collection.rb, line 54 def [] key self.to_h[key] end
[]=(key, value)
click to toggle source
@param [String] key @param [String] value
# File lib/aws/s3/bucket_tag_collection.rb, line 60 def []= key, value self.set(self.to_h.merge(key => value)) end
clear()
click to toggle source
Removes all tags from the bucket.
@example
bucket.tags.clear bucket.tags.to_h #=> {}
@return [nil]
# File lib/aws/s3/bucket_tag_collection.rb, line 83 def clear client.delete_bucket_tagging(:bucket_name => bucket.name) nil end
eql?(other)
click to toggle source
@param [Hash] other @return [Boolean] Returns ‘true` if the tags for this bucket match
the passed hash.
# File lib/aws/s3/bucket_tag_collection.rb, line 99 def eql? other self.to_h == other end
Also aliased as: ==
inspect()
click to toggle source
@api private
# File lib/aws/s3/bucket_tag_collection.rb, line 105 def inspect self.to_h.inspect end
set(tags)
click to toggle source
@param [Hash<String,String>] tags A hash of tag keys and values. @return [nil]
# File lib/aws/s3/bucket_tag_collection.rb, line 66 def set tags if tags.nil? or tags.empty? self.clear else client.put_bucket_tagging(:bucket_name => bucket.name, :tags => tags) end nil end
to_h()
click to toggle source
@return [Hash]
# File lib/aws/s3/bucket_tag_collection.rb, line 89 def to_h client.get_bucket_tagging(:bucket_name => bucket.name).data[:tags] rescue AWS::S3::Errors::NoSuchTagSet {} end
Also aliased as: to_hash