Class: R10kDiff::PuppetfileDiff
- Inherits:
-
Object
- Object
- R10kDiff::PuppetfileDiff
- Defined in:
- lib/r10kdiff.rb
Instance Method Summary collapse
- #additions ⇒ Object
- #changes ⇒ Object
-
#initialize(oldfile, newfile) ⇒ PuppetfileDiff
constructor
Represents the difference between the puppetfile from one commit to another.
- #print_differences(include_url) ⇒ Object
- #removals ⇒ Object
Constructor Details
#initialize(oldfile, newfile) ⇒ PuppetfileDiff
Represents the difference between the puppetfile from one commit to another
86 87 88 89 |
# File 'lib/r10kdiff.rb', line 86 def initialize(oldfile, newfile) @oldfile = oldfile @newfile = newfile end |
Instance Method Details
#additions ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/r10kdiff.rb', line 102 def additions additions = [] @newfile.modules.each do |name, new_module| additions << new_module unless @oldfile.modules[name] end additions end |
#changes ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/r10kdiff.rb', line 91 def changes changed_modules = [] modules_in_common = Set.new(@oldfile.modules.keys).intersection Set.new(@newfile.modules.keys) modules_in_common.each do |name| new_module = @newfile.modules[name] old_module = @oldfile.modules[name] changed_modules << [old_module, new_module] if new_module.different? old_module end changed_modules end |
#print_differences(include_url) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/r10kdiff.rb', line 118 def print_differences(include_url) # Print the additions, removals, and changes output = [] puppetfile_changes = false if removals.length > 0 puppetfile_changes = true output << "Remove:" end removals.each do |old| output << " #{old.pretty_version(include_url)}" end if additions.length > 0 puppetfile_changes = true output << "Add:" end additions.each do |new| output << " #{new.pretty_version(include_url)}" end if changes.length > 0 puppetfile_changes = true output << "Change:" end changes.each do |old, new| output << " #{new.pretty_version_diff(old, include_url)}" end if !puppetfile_changes output << "No changes in Puppetfile" end output.each { |x| puts x } end |
#removals ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/r10kdiff.rb', line 110 def removals removals = [] @oldfile.modules.each do |name, old_module| removals << old_module unless @newfile.modules[name] end removals end |