Class: Stackup::Differ
- Inherits:
-
Object
- Object
- Stackup::Differ
- Defined in:
- lib/stackup/differ.rb
Overview
Generates diffs of data.
Instance Attribute Summary collapse
-
#diff_style ⇒ Object
readonly
Returns the value of attribute diff_style.
Instance Method Summary collapse
- #diff(existing_data, pending_data) ⇒ Object
-
#initialize(diff_style = :color, &data_formatter) ⇒ Differ
constructor
A new instance of Differ.
Constructor Details
#initialize(diff_style = :color, &data_formatter) ⇒ Differ
Returns a new instance of Differ.
10 11 12 13 |
# File 'lib/stackup/differ.rb', line 10 def initialize(diff_style = :color, &data_formatter) @diff_style = diff_style.to_sym @data_formatter = data_formatter || YAML.method(:dump) end |
Instance Attribute Details
#diff_style ⇒ Object (readonly)
Returns the value of attribute diff_style.
15 16 17 |
# File 'lib/stackup/differ.rb', line 15 def diff_style @diff_style end |
Instance Method Details
#diff(existing_data, pending_data) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/stackup/differ.rb', line 17 def diff(existing_data, pending_data) existing = format(existing_data) + "\n" pending = format(pending_data) + "\n" diff = Diffy::Diff.new(existing, pending).to_s(diff_style) diff unless diff =~ /\A\s*\Z/ end |