Class: AWS::ELB::LoadBalancerTagCollection
- Inherits:
-
Object
- Object
- AWS::ELB::LoadBalancerTagCollection
- Includes:
- Core::Model, Enumerable
- Defined in:
- lib/aws/elb/load_balancer_tag_collection.rb
Overview
Represents the ELB tags associated with a single load balancer.
Instance Method Summary collapse
-
#[](key) ⇒ String
The value of the tag with the given key, or nil if no such tag exists.
-
#[]=(key, value) ⇒ Object
(also: #store)
Changes the value of a tag.
-
#add(key) ⇒ Object
(also: #<<)
Adds a tag with a blank value.
-
#clear ⇒ Object
Removes all tags from the resource.
-
#delete(*keys) ⇒ Object
Deletes the tags with the given keys (which may be strings or symbols).
- #each {|key, value| ... } ⇒ Object (also: #each_pair)
-
#empty? ⇒ Boolean
True if the resource has no tags.
-
#has_key?(key) ⇒ Boolean
(also: #key?, #include?, #member?)
True if the resource has a tag for the given key.
-
#has_value?(value) ⇒ Boolean
(also: #value?)
True if the resource has a tag with the given value.
-
#initialize(load_balancer, opts = {}) ⇒ LoadBalancerTagCollection
constructor
private
A new instance of LoadBalancerTagCollection.
-
#method_missing(m, *args) ⇒ Object
Allows setting and getting individual tags through instance methods.
-
#set(tags) ⇒ Object
(also: #update)
Sets multiple tags in a single request.
-
#values_at(*keys) ⇒ Array
An array of the tag values associated with the given keys.
Constructor Details
#initialize(load_balancer, opts = {}) ⇒ LoadBalancerTagCollection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of LoadBalancerTagCollection.
18 19 20 21 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 18 def initialize(load_balancer, opts = {}) @load_balancer_name = load_balancer.name super(opts) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
Allows setting and getting individual tags through instance methods. For example:
.color = "red"
.color # => "red"
93 94 95 96 97 98 99 100 101 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 93 def method_missing(m, *args) if m.to_s[-1,1] == "=" self.send(:[]=, m.to_s[0...-1], *args) elsif args.empty? self[m] else super end end |
Instance Method Details
#[](key) ⇒ String
Returns The value of the tag with the given key, or nil if no such tag exists.
27 28 29 30 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 27 def [](key) each { |k, v| return v if k == key.to_s } nil end |
#[]=(key, value) ⇒ Object Also known as: store
Changes the value of a tag.
57 58 59 60 61 62 63 64 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 57 def []=(key, value) if value set(key => value) else delete(key) end nil # Unlike EC2 version, this does not return a Tag object end |
#add(key) ⇒ Object Also known as: <<
Adds a tag with a blank value.
70 71 72 73 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 70 def add(key) self[key] = '' nil # Unlike EC2 version, this does not return a Tag object end |
#clear ⇒ Object
Removes all tags from the resource.
112 113 114 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 112 def clear delete *map(&:first) end |
#delete(*keys) ⇒ Object
Deletes the tags with the given keys (which may be strings or symbols).
105 106 107 108 109 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 105 def delete(*keys) return if keys.empty? keys = keys.map { |k, v| { :key => k.to_s } } client. api_args.merge(:tags => keys) end |
#each {|key, value| ... } ⇒ Object Also known as: each_pair
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 119 def each(&blk) td = client.(api_args)[:tag_descriptions] = td.detect { |t| t[:load_balancer_name] == @load_balancer_name } or return [:tags].each do |t| k, v = t.values_at(:key, :value).map(&:to_s) if blk.arity == 2 yield(k, v) else yield([k, v]) end end nil end |
#empty? ⇒ Boolean
Returns True if the resource has no tags.
33 34 35 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 33 def empty? any? end |
#has_key?(key) ⇒ Boolean Also known as: key?, include?, member?
Returns True if the resource has a tag for the given key.
39 40 41 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 39 def has_key?(key) any? { |k, v| k == key.to_s } end |
#has_value?(value) ⇒ Boolean Also known as: value?
Returns True if the resource has a tag with the given value.
48 49 50 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 48 def has_value?(value) any? { |k, v| v == value.to_s } end |
#set(tags) ⇒ Object Also known as: update
Sets multiple tags in a single request.
82 83 84 85 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 82 def set() = .map { |k, v| { :key => k.to_s, :value => v.to_s } } client. api_args.merge(:tags => ) end |
#values_at(*keys) ⇒ Array
Returns An array of the tag values associated with the given keys. An entry for a key that has no value (i.e. there is no such tag) will be nil.
137 138 139 140 141 142 |
# File 'lib/aws/elb/load_balancer_tag_collection.rb', line 137 def values_at(*keys) hash = to_h keys.map do |key| hash[key.to_s] end end |