Class: Cumulus::CloudFront::DistributionDiff

Inherits:
Cumulus::Common::Diff show all
Includes:
DistributionChange
Defined in:
lib/cloudfront/models/DistributionDiff.rb

Overview

Public: Represents a single difference between local configuration and AWS configuration of zones.

Constant Summary

Constants included from DistributionChange

Cumulus::CloudFront::DistributionChange::ALIASES, Cumulus::CloudFront::DistributionChange::CACHES, Cumulus::CloudFront::DistributionChange::CACHE_DEFAULT, Cumulus::CloudFront::DistributionChange::COMMENT, Cumulus::CloudFront::DistributionChange::ENABLED, Cumulus::CloudFront::DistributionChange::ORIGINS

Constants included from Cumulus::Common::DiffChange

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

Instance Attribute Summary collapse

Attributes inherited from Cumulus::Common::Diff

#aws, #changes, #info_only, #local, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cumulus::Common::DiffChange

next_change_id

Methods inherited from Cumulus::Common::Diff

#add_string, added, #initialize, #local_name, modified, #to_s, unmanaged, #unmanaged_string

Constructor Details

This class inherits a constructor from Cumulus::Common::Diff

Instance Attribute Details

#added_aliasesObject

Returns the value of attribute added_aliases.



26
27
28
# File 'lib/cloudfront/models/DistributionDiff.rb', line 26

def added_aliases
  @added_aliases
end

#cacheObject

Returns the value of attribute cache.



29
30
31
# File 'lib/cloudfront/models/DistributionDiff.rb', line 29

def cache
  @cache
end

#changed_originsObject

Returns the value of attribute changed_origins.



25
26
27
# File 'lib/cloudfront/models/DistributionDiff.rb', line 25

def changed_origins
  @changed_origins
end

#default_cacheObject

Returns the value of attribute default_cache.



28
29
30
# File 'lib/cloudfront/models/DistributionDiff.rb', line 28

def default_cache
  @default_cache
end

#removed_aliasesObject

Returns the value of attribute removed_aliases.



27
28
29
# File 'lib/cloudfront/models/DistributionDiff.rb', line 27

def removed_aliases
  @removed_aliases
end

Class Method Details

.aliases(added, removed, local) ⇒ Object



43
44
45
46
47
48
# File 'lib/cloudfront/models/DistributionDiff.rb', line 43

def self.aliases(added, removed, local)
  diff = DistributionDiff.new(ALIASES, nil, local)
  diff.added_aliases = added
  diff.removed_aliases = removed
  diff
end

.caches(removed, added, diffs, local) ⇒ Object



56
57
58
59
60
# File 'lib/cloudfront/models/DistributionDiff.rb', line 56

def self.caches(removed, added, diffs, local)
  diff = DistributionDiff.new(CACHES, nil, local)
  diff.cache = Common::ListChange.new(removed, added, diffs)
  diff
end

.default_cache(diffs, local) ⇒ Object



50
51
52
53
54
# File 'lib/cloudfront/models/DistributionDiff.rb', line 50

def self.default_cache(diffs, local)
  diff = DistributionDiff.new(CACHE_DEFAULT, nil, local)
  diff.default_cache = diffs
  diff
end

.origins(changes, local) ⇒ Object

Public: Static method that produces a diff representing changes in origins

changes - the OriginDiffs local - the local configuration for the distribution

Returns the diff



37
38
39
40
41
# File 'lib/cloudfront/models/DistributionDiff.rb', line 37

def self.origins(changes, local)
  diff = DistributionDiff.new(ORIGINS, nil, local)
  diff.changed_origins = changes
  diff
end

Instance Method Details

#asset_typeObject



120
121
122
# File 'lib/cloudfront/models/DistributionDiff.rb', line 120

def asset_type
  "Cloudfront Distribution"
end

#aws_nameObject



124
125
126
# File 'lib/cloudfront/models/DistributionDiff.rb', line 124

def aws_name
  @aws.id
end

#diff_stringObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/cloudfront/models/DistributionDiff.rb', line 62

def diff_string
  case @type
  when ALIASES
    [
      "aliases:",
      @removed_aliases.map { |removed| Colors.removed("\t#{removed}") },
      @added_aliases.map { |added| Colors.added("\t#{added}") },
    ].flatten.join("\n")
  when ORIGINS
    [
      "origins:",
      @changed_origins.map do |o|
        if o.type == ADD or o.type == UNMANAGED
          o.to_s.lines.map { |l| "\t#{l}".chomp("\n")}
        else
          [
            "\t#{o.local_name}",
            o.to_s.lines.map { |l| "\t\t#{l}".chomp("\n")}
          ].join("\n")
        end
      end
    ].flatten.join("\n")
  when CACHE_DEFAULT
    [
      "default cache behavior:",
      (@default_cache.map do |c|
        c.to_s.lines.map { |l| "\t#{l}".chomp("\n")}
      end).join("\n"),
    ].join("\n")
  when CACHES
    [
      "cache behaviors:",
      @cache.removed.map { |removed| Colors.removed("\t#{removed}") },
      @cache.added.map { |added| Colors.added("\t#{added}") },
      @cache.modified.map do |cache_name, cdiffs|
        [
          "\t#{cache_name}",
          cdiffs.map do |cdiff|
            cdiff.to_s.lines.map { |l| "\t\t#{l.chomp}"}
          end
        ]
      end
    ].flatten.join("\n")
  when COMMENT
    [
      "comment:",
      Colors.aws_changes("\tAWS - #{@aws.comment}"),
      Colors.local_changes("\tLocal - #{@local.comment}"),
    ].join("\n")
  when ENABLED
    [
      "enabled:",
      Colors.aws_changes("\tAWS - #{@aws.enabled}"),
      Colors.local_changes("\tLocal - #{@local.enabled}"),
    ].join("\n")
  end
end