Class: Black::Diff
Defined Under Namespace
Modules: OutputParser Classes: Line
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#newer ⇒ Object
readonly
Returns the value of attribute newer.
-
#older ⇒ Object
readonly
Returns the value of attribute older.
Class Method Summary collapse
-
.execute(*command_args) ⇒ Object
wrapper to execute ‘diff` in the shell.
Instance Method Summary collapse
- #diff_parsed ⇒ Object
- #each ⇒ Object
-
#execute ⇒ Object
diff two strings using unix ‘diff’ command.
-
#initialize(older, newer, filename = nil) ⇒ Diff
constructor
A new instance of Diff.
Constructor Details
#initialize(older, newer, filename = nil) ⇒ Diff
Returns a new instance of Diff.
13 14 15 16 17 |
# File 'lib/black/diff.rb', line 13 def initialize(older, newer, filename=nil) @older = older @newer = newer @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
11 12 13 |
# File 'lib/black/diff.rb', line 11 def filename @filename end |
#newer ⇒ Object (readonly)
Returns the value of attribute newer.
11 12 13 |
# File 'lib/black/diff.rb', line 11 def newer @newer end |
#older ⇒ Object (readonly)
Returns the value of attribute older.
11 12 13 |
# File 'lib/black/diff.rb', line 11 def older @older end |
Class Method Details
.execute(*command_args) ⇒ Object
wrapper to execute ‘diff` in the shell. Reimplement this to suit your own platform needs
5 6 7 |
# File 'lib/black/diff.rb', line 5 def self.execute(*command_args) `diff #{ command_args.join(' ') }` end |
Instance Method Details
#diff_parsed ⇒ Object
48 49 50 |
# File 'lib/black/diff.rb', line 48 def diff_parsed OutputParser.parse(execute.enum_for(:lines)) end |
#each ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/black/diff.rb', line 19 def each if block_given? diff_parsed.each do |line| yield line end else diff_parsed.enum_for(:each) end end |
#execute ⇒ Object
diff two strings using unix ‘diff’ command
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/black/diff.rb', line 30 def execute files = [Tempfile.new('black'), Tempfile.new('black')] files.first.write(@older) files.last.write(@newer) files.each { |a| a.read } args = [files.first.path, files.last.path] + OutputParser. Diff.execute(args) ensure files.each do |file| if file && File.exist?(file.path) file.close file.unlink end end end |