Module: AWS::EC2::TaggedItem
- Included in:
- CustomerGateway, DHCPOptions, Image, Instance, InternetGateway, NetworkACL, NetworkInterface, ReservedInstances, ReservedInstancesOffering, ResourceObject, RouteTable, SecurityGroup, Snapshot, Subnet, VPC, VPNConnection, VPNGateway, Volume
- Defined in:
- lib/aws/ec2/tagged_item.rb
Instance Method Summary collapse
-
#add_tag(key, options = {}) ⇒ Tag
(also: #tag)
Adds a single tag with an optional tag value.
- #cached_tags ⇒ Object
-
#clear_tags ⇒ nil
Deletes all tags associated with this EC2 resource.
- #tagging_resource_type ⇒ Object
-
#tags ⇒ ResourceTagCollection
Returns a collection that represents only tags belonging to this resource.
Instance Method Details
#add_tag(key, options = {}) ⇒ Tag Also known as: tag
Adds a single tag with an optional tag value.
# adds a tag with the key production
resource.tag('production')
# adds a tag with the optional value set to production
resource.tag('role', :value => 'webserver')
30 31 32 33 34 35 36 |
# File 'lib/aws/ec2/tagged_item.rb', line 30 def add_tag key, = {} client.({ :resources => [id], :tags => [{ :key => key, :value => [:value].to_s }], }) Tag.new(self, key, .merge(:config => config)) end |
#cached_tags ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aws/ec2/tagged_item.rb', line 64 def if cache = AWS.response_cache cache.select(describe_call_name.to_sym).each do |resp| if obj = find_in_response(resp) return obj.tag_set.inject({}) do |hash, tag| hash[tag.key] = tag.value hash end end end end nil end |
#clear_tags ⇒ nil
Deletes all tags associated with this EC2 resource.
41 42 43 44 |
# File 'lib/aws/ec2/tagged_item.rb', line 41 def client.(:resources => [self.id]) nil end |
#tagging_resource_type ⇒ Object
79 80 81 |
# File 'lib/aws/ec2/tagged_item.rb', line 79 def tagging_resource_type Core::Inflection.ruby_name(self.class.to_s).tr("_","-") end |
#tags ⇒ ResourceTagCollection
Returns a collection that represents only tags belonging to this resource.
59 60 61 |
# File 'lib/aws/ec2/tagged_item.rb', line 59 def ResourceTagCollection.new(self, :config => config) end |