class Cumulus::Common::Diff

Public: The base class for all Diff classes.

To extend this class, do the following:

  1. Provide a `diff_string` method. This method will be called if the default to_s method cannot produce a result.

  2. Provide a `asset_type` method. This method should return the string type of asset for which this is a diff.

  3. Provide an `aws_name` method. This method should give back the string name of the aws asset.

  4. (Optional) Replace the existing `local_name` method. This method produces the string name of the local asset. Defaults to `name` on the local asset.

Attributes

aws[R]
changes[RW]
info_only[RW]
local[R]
type[R]

Public Class Methods

added(local) click to toggle source

Public: Static method that will produce an “added” diff

local - the local configuration that is added

Returns the diff

# File lib/common/models/Diff.rb, line 55
def self.added(local)
  self.new(ADD, nil, local)
end
modified(aws, local, changes) click to toggle source

Public: Static method that will produce a “modified” diff

local - the local configuration aws - the aws resource changes - an object describing what was modified

# File lib/common/models/Diff.rb, line 64
def self.modified(aws, local, changes)
  self.new(MODIFIED, aws, local, changes)
end
new(type, aws = nil, local = nil, changes = nil) click to toggle source

Public: Constructor

type - the type of the difference aws - the aws resource that's different (defaults to nil) local - the local resource that's difference (defaults to nil) changes - an object to describe what changed in a MODIFIED diff (defaults to nil)

# File lib/common/models/Diff.rb, line 74
def initialize(type, aws = nil, local = nil, changes = nil)
  @aws = aws
  @local = local
  @type = type
  @changes = changes
  @info_only = false
end
unmanaged(aws) click to toggle source

Public: Static method that will produce an “unmanaged” diff

aws - the aws resource that is unmanaged

Returns the diff

# File lib/common/models/Diff.rb, line 46
def self.unmanaged(aws)
  self.new(UNMANAGED, aws)
end

Public Instance Methods

add_string() click to toggle source

Public: A method that produces the string that describes what will be done with new assets. This can be overridden for the case that the ADD case doesn't create the asset.

Returns the string describing the action that will be taken.

# File lib/common/models/Diff.rb, line 97
def add_string
  "will be created."
end
local_name() click to toggle source
# File lib/common/models/Diff.rb, line 109
def local_name
  @local.name
end
to_s() click to toggle source
# File lib/common/models/Diff.rb, line 82
def to_s
  case @type
  when ADD
    Colors.added("#{asset_type} #{local_name} #{add_string}")
  when UNMANAGED
    Colors.unmanaged("#{asset_type} #{aws_name} #{unmanaged_string}")
  else
    diff_string
  end
end
unmanaged_string() click to toggle source

Public: A method that produces the string that describes what will be done with unmanaged assets. This can be overriden for the case that the UNMANAGED case does not ignore the asset.

Returns the string describing the action that will be taken

# File lib/common/models/Diff.rb, line 105
def unmanaged_string
  "is not managed by Cumulus."
end