Class: AWS::EC2::Tag

Inherits:
Resource show all
Defined in:
lib/aws/ec2/tag.rb

Overview

Represents an EC2 tag.

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods inherited from Core::Resource

attribute_providers, attribute_providers_for, attributes, #attributes_from_response, define_attribute_type, #eql?, new_from

Methods included from Core::Cacheable

included, #retrieve_attribute

Methods included from Core::Model

#client, #config_prefix

Constructor Details

#initialize(resource, key, options = {}) ⇒ Tag

Returns a new instance of Tag.

Parameters:

  • key (String)

    The name of the tag

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :value (String) — default: ''

    The optional value of the tag.



24
25
26
27
28
# File 'lib/aws/ec2/tag.rb', line 24

def initialize resource, key, options = {}
  @resource = resource
  @key = key.to_s
  super
end

Instance Attribute Details

#keyString (readonly) Also known as: name

Returns The name of this tag.

Returns:

  • (String)

    The name of this tag.



34
35
36
# File 'lib/aws/ec2/tag.rb', line 34

def key
  @key
end

#resourceObject (readonly)

Returns The EC2 resource this tag belongs to.

Returns:

  • (Object)

    The EC2 resource this tag belongs to.



31
32
33
# File 'lib/aws/ec2/tag.rb', line 31

def resource
  @resource
end

#valueString

The tag value.

Returns:

  • (String)

    the current value of value



19
20
21
# File 'lib/aws/ec2/tag.rb', line 19

def value
  @value
end

Instance Method Details

#delete(value = nil) ⇒ nil

Deletes this tag.

Returns:

  • (nil)


46
47
48
49
50
51
# File 'lib/aws/ec2/tag.rb', line 46

def delete(value = nil)
  tag_opts = { :key => key }
  tag_opts[:value] = value if value
  client.delete_tags(:resources => [resource.id], :tags => [tag_opts])
  nil
end

#inspectObject



54
55
56
# File 'lib/aws/ec2/tag.rb', line 54

def inspect
  "<#{self.class}:#{local_cache_key}>"
end

#local_cache_keyObject



59
60
61
# File 'lib/aws/ec2/tag.rb', line 59

def local_cache_key
  response_index_key
end