Class: StackMaster::Diff
- Inherits:
-
Object
- Object
- StackMaster::Diff
- Extended by:
- Forwardable
- Defined in:
- lib/stack_master/diff.rb
Instance Method Summary collapse
- #different? ⇒ Boolean
- #display ⇒ Object
- #display_colorized_diff ⇒ Object
-
#initialize(name: nil, before:, after:, context: 10_000) ⇒ Diff
constructor
A new instance of Diff.
Constructor Details
#initialize(name: nil, before:, after:, context: 10_000) ⇒ Diff
Returns a new instance of Diff.
3 4 5 6 7 8 |
# File 'lib/stack_master/diff.rb', line 3 def initialize(name: nil, before:, after:, context: 10_000) @name = name @before = before @after = after @context = context end |
Instance Method Details
#different? ⇒ Boolean
32 33 34 |
# File 'lib/stack_master/diff.rb', line 32 def different? diff != '' end |
#display ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/stack_master/diff.rb', line 10 def display stdout.print "#{@name} diff: " if diff == '' stdout.puts "No changes" else stdout.puts display_colorized_diff end end |
#display_colorized_diff ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/stack_master/diff.rb', line 20 def display_colorized_diff diff.each_line do |line| if line.start_with?('+') stdout.print colorize(line, :green) elsif line.start_with?('-') stdout.print colorize(line, :red) else stdout.print line end end end |