Class: ElasticGraph::Indexer::HashDiffer
- Inherits:
-
Object
- Object
- ElasticGraph::Indexer::HashDiffer
- Defined in:
- lib/elastic_graph/indexer/hash_differ.rb
Class Method Summary collapse
-
.diff(old, new, ignore_ops: []) ⇒ Object
Generates a string describing how ‘old` and `new` differ, similar to a git diff.
Class Method Details
.diff(old, new, ignore_ops: []) ⇒ Object
Generates a string describing how ‘old` and `new` differ, similar to a git diff. `ignore_ops` can contain any of `:-`, `:+`, and `:~`; when provided those diff operations will be ignored.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/elastic_graph/indexer/hash_differ.rb', line 17 def self.diff(old, new, ignore_ops: []) ignore_op_strings = ignore_ops.map(&:to_s).to_set diffs = ::Hashdiff.diff(old, new) .reject { |op, path, *vals| ignore_op_strings.include?(_ = op) } return if diffs.empty? diffs.map do |op, path, *vals| suffix = if vals.one? vals.first else vals.map { |v| "`#{v.inspect}`" }.join(" => ") end "#{op} #{path}: #{suffix}" end.join("\n") end |