Class: OpenStax::Aws::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax/aws/tag.rb

Constant Summary collapse

AWS_TAG_KEY_REGEX =
/\A[\w\-\/.+=:@]{1,128}\z/
AWS_TAG_VALUE_REGEX =
/\A[\w\-\/.+=:@ ]{0,256}\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ Tag

Returns a new instance of Tag.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/openstax/aws/tag.rb', line 9

def initialize(key, value)
  if key.nil? || !key.match(AWS_TAG_KEY_REGEX)
    raise "The tag key '#{key}' is invalid: must be a non-blank ID matching #{AWS_TAG_KEY_REGEX}"
  end

  @key = key.to_s

  if @key.starts_with?("aws:")
    raise "The tag key '#{@key}' is invalid: it cannot start with 'aws:'"
  end

  if value.nil?
    raise "The tag value for key '#{key}' cannot be nil"
  end

  if !value.match(AWS_TAG_VALUE_REGEX)
    raise "The tag value '#{value}' must be a tag value matching #{AWS_TAG_VALUE_REGEX}"
  end

  @value = value.to_s
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/openstax/aws/tag.rb', line 4

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/openstax/aws/tag.rb', line 4

def value
  @value
end