Class: Cumulus::Common::Diff

Inherits:
Object
  • Object
show all
Includes:
DiffChange
Defined in:
lib/common/models/Diff.rb

Overview

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.

Constant Summary

Constants included from DiffChange

Cumulus::Common::DiffChange::ADD, Cumulus::Common::DiffChange::MODIFIED, Cumulus::Common::DiffChange::UNMANAGED

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DiffChange

next_change_id

Constructor Details

#initialize(type, aws = nil, local = nil, changes = nil) ⇒ Diff

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)



74
75
76
77
78
79
80
# 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

Instance Attribute Details

#awsObject (readonly)

Returns the value of attribute aws.



38
39
40
# File 'lib/common/models/Diff.rb', line 38

def aws
  @aws
end

#changesObject

Returns the value of attribute changes.



39
40
41
# File 'lib/common/models/Diff.rb', line 39

def changes
  @changes
end

#info_onlyObject

Returns the value of attribute info_only.



39
40
41
# File 'lib/common/models/Diff.rb', line 39

def info_only
  @info_only
end

#localObject (readonly)

Returns the value of attribute local.



38
39
40
# File 'lib/common/models/Diff.rb', line 38

def local
  @local
end

#typeObject (readonly)

Returns the value of attribute type.



38
39
40
# File 'lib/common/models/Diff.rb', line 38

def type
  @type
end

Class Method Details

.added(local) ⇒ Object

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

local - the local configuration that is added

Returns the diff



55
56
57
# File 'lib/common/models/Diff.rb', line 55

def self.added(local)
  self.new(ADD, nil, local)
end

.modified(aws, local, changes) ⇒ Object

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

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



64
65
66
# File 'lib/common/models/Diff.rb', line 64

def self.modified(aws, local, changes)
  self.new(MODIFIED, aws, local, changes)
end

.unmanaged(aws) ⇒ Object

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

aws - the aws resource that is unmanaged

Returns the diff



46
47
48
# File 'lib/common/models/Diff.rb', line 46

def self.unmanaged(aws)
  self.new(UNMANAGED, aws)
end

Instance Method Details

#add_stringObject

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.



97
98
99
# File 'lib/common/models/Diff.rb', line 97

def add_string
  "will be created."
end

#local_nameObject



109
110
111
# File 'lib/common/models/Diff.rb', line 109

def local_name
  @local.name
end

#to_sObject



82
83
84
85
86
87
88
89
90
91
# 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_stringObject

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



105
106
107
# File 'lib/common/models/Diff.rb', line 105

def unmanaged_string
  "is not managed by Cumulus."
end