Class: OctocatalogDiff::CatalogDiff::Filter::CompilationDir
- Inherits:
-
OctocatalogDiff::CatalogDiff::Filter
- Object
- OctocatalogDiff::CatalogDiff::Filter
- OctocatalogDiff::CatalogDiff::Filter::CompilationDir
- Defined in:
- lib/octocatalog-diff/catalog-diff/filter/compilation_dir.rb
Overview
Filter out changes that are due to the catalog compilation directory.
Constant Summary
Constants inherited from OctocatalogDiff::CatalogDiff::Filter
Instance Attribute Summary
Attributes inherited from OctocatalogDiff::CatalogDiff::Filter
Instance Method Summary collapse
-
#filtered?(diff, options = {}) ⇒ Boolean
Public: Filter the diff if the change is due to the catalog compilation directory.
- #remove_compilation_dir(v, dir) ⇒ Object
- #traverse(a) ⇒ Object
Methods inherited from OctocatalogDiff::CatalogDiff::Filter
apply_filters, assert_that_filter_exists, filter, filter?, #initialize
Constructor Details
This class inherits a constructor from OctocatalogDiff::CatalogDiff::Filter
Instance Method Details
#filtered?(diff, options = {}) ⇒ Boolean
Public: Filter the diff if the change is due to the catalog compilation directory. Determine this by obtaining the compiilation directory from each of the catalogs (supplied via options) and checking the differences. If the only thing different is the compilation directory, filter it out with a warning.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/octocatalog-diff/catalog-diff/filter/compilation_dir.rb', line 21 def filtered?(diff, = {}) return false unless [:from_compilation_dir] && [:to_compilation_dir] dir1 = [:to_compilation_dir] dir1_rexp = Regexp.escape(dir1) dir2 = [:from_compilation_dir] dir2_rexp = Regexp.escape(dir2) dir = Regexp.new("(?:#{dir1_rexp}|#{dir2_rexp})") # Check for added/removed resources where the title of the resource includes the compilation directory if (diff.addition? || diff.removal?) && diff.title.match(dir) = "Resource #{diff.type}[#{diff.title}]" += ' appears to depend on catalog compilation directory. Suppressed from results.' logger.warn return true end # Check for a change where the difference in a parameter exactly corresponds to the difference in the # compilation directory. if diff.change? o = remove_compilation_dir(diff.old_value, dir2) n = remove_compilation_dir(diff.new_value, dir1) if o != diff.old_value || n != diff.new_value = "Resource key #{diff.type}[#{diff.title}] #{diff.structure.join(' => ')}" += ' may depend on catalog compilation directory, but there may be differences.' += ' This is included in results for now, but please verify.' @logger.warn end if o == n = "Resource key #{diff.type}[#{diff.title}] #{diff.structure.join(' => ')}" += ' appears to depend on catalog compilation directory. Suppressed from results.' @logger.warn return true end end false end |
#remove_compilation_dir(v, dir) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/octocatalog-diff/catalog-diff/filter/compilation_dir.rb', line 61 def remove_compilation_dir(v, dir) value = OctocatalogDiff::Util::Util.deep_dup(v) traverse(value) do |e| e.gsub!(dir, '') if e.respond_to?(:gsub!) end value end |
#traverse(a) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/octocatalog-diff/catalog-diff/filter/compilation_dir.rb', line 69 def traverse(a) case a when Array a.map { |v| traverse(v, &Proc.new) } when Hash traverse(a.values, &Proc.new) else yield a end end |