module Cumulus::Common::TagsDiff

Public: A module to be mixed in to Diff classes that have tags

Public Instance Methods

tags_diff_string() click to toggle source

Public: Get the diff string for tag differences

Returns the string to display

# File lib/common/models/TagsDiff.rb, line 8
def tags_diff_string
  lines = ["Tags:"]
  lines << tags_to_remove.map { |k, v| "\t#{Colors.removed("#{k} => #{v}")}" }
  lines << tags_to_add.map { |k, v| "\t#{Colors.added("#{k} => #{v}")}" }
  lines.flatten.join("\n")
end
tags_to_add() click to toggle source

Public: Get the tags that are in local configuration but not in AWS

Returns a hash of tags

# File lib/common/models/TagsDiff.rb, line 25
def tags_to_add
  local_tags.reject { |t, v| aws_tags.include?(t) and aws_tags[t] == v }
end
tags_to_remove() click to toggle source

Public: Get the tags that are in AWS that are not in local configuration

Returns a hash of tags

# File lib/common/models/TagsDiff.rb, line 18
def tags_to_remove
  aws_tags.reject { |t, v| local_tags.include?(t) and local_tags[t] == v }
end

Private Instance Methods

aws_tags() click to toggle source

Internal: Get the tags in AWS as a hash of key to value

Returns a hash of tags

# File lib/common/models/TagsDiff.rb, line 42
def aws_tags
  @aws_tags ||= Hash[aws_tags_list.map { |tag| [tag.key, tag.value] }]
end
aws_tags_list() click to toggle source

Internal: Override this method if tags are not found on the tags attribute of the aws object.

Returns the tags

# File lib/common/models/TagsDiff.rb, line 50
def aws_tags_list
  @aws.tags
end
local_tags() click to toggle source

Internal: Override this method if the tags are not found on the tags attribute of the local object

Returns the tags

# File lib/common/models/TagsDiff.rb, line 35
def local_tags
  @local.tags
end