class AWS::EC2::TagCollection
Represents all EC2
tags in an account.
Public Instance Methods
[](tag_name)
click to toggle source
@return [Tag] Returns a reference to a tag with the given name.
Calls superclass method
AWS::EC2::Collection#[]
# File lib/aws/ec2/tag_collection.rb, line 71 def [] tag_name super end
create(resource, key, options = {})
click to toggle source
Creates a new Tag
and assigns it to an EC2
resource.
@example tagging with names (keys) only
ec2.tags.create(instance, 'webserver')
@example tagging with names (keys) and values
ec2.tags.create(instance, 'stage', :value => 'production')
@param [Object] resource The item to tag. This should be a taggable
EC2 resource, like an instance, security group, etc.
@param [String] key The tag key (or name). @param [Hash] options @option optins [String] :value ('') The optional tag value. When
left blank its assigned the empty string.
@return [Tag]
# File lib/aws/ec2/tag_collection.rb, line 62 def create resource, key, options = {} value = options[:value].to_s client.create_tags( :resources => [resource.id], :tags => [{ :key => key, :value => value }]) Tag.new(resource, key, :value => value, :config => config) end
each() { |tag| ... }
click to toggle source
Yields once for each tag. @yield [tag] @yieldparam [Tag] tag @return [nil]
# File lib/aws/ec2/tag_collection.rb, line 79 def each &block response = filtered_request(:describe_tags) response.tag_set.each do |tag| resource_class_name = Core::Inflection.class_name(tag.resource_type) if EC2.const_defined?(resource_class_name) resource_class = EC2.const_get(resource_class_name) resource = resource_class.new(tag.resource_id, :config => config) else resource = ResourceObject.new(tag.resource_id, :resource_type => tag.resource_type, :config => config) end yield(Tag.new(resource, tag.key)) end nil end
Protected Instance Methods
member_class()
click to toggle source
@api private
# File lib/aws/ec2/tag_collection.rb, line 101 def member_class Tag end