Class: AWS::EC2::TagCollection
- Inherits:
-
Collection
- Object
- Collection
- AWS::EC2::TagCollection
- Defined in:
- lib/aws/ec2/tag_collection.rb
Overview
Represents all EC2 tags in an account.
Instance Method Summary collapse
-
#[](tag_name) ⇒ Tag
Returns a reference to a tag with the given name.
-
#create(resource, key, options = {}) ⇒ Tag
Creates a new Tag and assigns it to an EC2 resource.
-
#each {|tag| ... } ⇒ nil
Yields once for each tag.
Instance Method Details
#[](tag_name) ⇒ Tag
Returns a reference to a tag with the given name.
78 79 80 |
# File 'lib/aws/ec2/tag_collection.rb', line 78 def [] tag_name super end |
#create(resource, key, options = {}) ⇒ Tag
Creates a new Tag and assigns it to an EC2 resource.
69 70 71 72 73 74 75 |
# File 'lib/aws/ec2/tag_collection.rb', line 69 def create resource, key, = {} value = [:value].to_s client.( :resources => [resource.id], :tags => [{ :key => key, :value => value }]) Tag.new(resource, key, :value => value, :config => config) end |
#each {|tag| ... } ⇒ nil
Yields once for each tag.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/aws/ec2/tag_collection.rb', line 86 def each &block response = filtered_request(:describe_tags) response.tag_set.each do |tag| resource_class_name = 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 |