Class: Deprewriter::Diff
- Inherits:
-
Object
- Object
- Deprewriter::Diff
- Defined in:
- lib/deprewriter/diff.rb
Instance Attribute Summary collapse
-
#rewritten_source ⇒ Object
readonly
Returns the value of attribute rewritten_source.
Instance Method Summary collapse
- #different? ⇒ Boolean
- #id ⇒ Object
-
#initialize(source, rewritten_source, filepath, timestamp: Time.now) ⇒ Diff
constructor
A new instance of Diff.
- #to_s ⇒ Object
Constructor Details
#initialize(source, rewritten_source, filepath, timestamp: Time.now) ⇒ Diff
Returns a new instance of Diff.
10 11 12 13 14 15 |
# File 'lib/deprewriter/diff.rb', line 10 def initialize(source, rewritten_source, filepath, timestamp: Time.now) @source = source @rewritten_source = rewritten_source @filepath = filepath = end |
Instance Attribute Details
#rewritten_source ⇒ Object (readonly)
Returns the value of attribute rewritten_source.
8 9 10 |
# File 'lib/deprewriter/diff.rb', line 8 def rewritten_source @rewritten_source end |
Instance Method Details
#different? ⇒ Boolean
17 18 19 |
# File 'lib/deprewriter/diff.rb', line 17 def different? @source != @rewritten_source end |
#id ⇒ Object
36 37 38 |
# File 'lib/deprewriter/diff.rb', line 36 def id "deprewriter_#{Digest::MD5.hexdigest(to_s)}.patch" end |
#to_s ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/deprewriter/diff.rb', line 21 def to_s @output ||= begin original_diff = Diffy::Diff.new(@source, @rewritten_source, include_diff_info: true, diff: "-u").to_s # Create a header to indicate a filepath since original_diff doesn't contain a correct filepath = .strftime("%Y-%m-%d %H:%M:%S.%N %z") header = [ "--- #{@filepath}\t#{formatted_timestamp}", "+++ #{@filepath}\t#{formatted_timestamp}" ].join("\n") [header, original_diff.lines[2..].join].join("\n") end end |