Class: Manifestly::Diff

Inherits:
Object
  • Object
show all
Defined in:
lib/manifestly/diff.rb

Defined Under Namespace

Classes: File

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diff_string) ⇒ Diff

Returns a new instance of Diff.



49
50
51
52
53
54
# File 'lib/manifestly/diff.rb', line 49

def initialize(diff_string)
  file_strings = diff_string.split("diff --git ")
  file_strings.reject!(&:blank?)
  file_strings.reject!{|str| str.starts_with?("commit ")} # from 'git show' output
  @files = file_strings.collect{|file_string| File.new(file_string)}
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



56
57
58
# File 'lib/manifestly/diff.rb', line 56

def files
  @files
end

Instance Method Details

#[](index) ⇒ Object



66
67
68
# File 'lib/manifestly/diff.rb', line 66

def [](index)
  files[index]
end

#has_file?(filename) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/manifestly/diff.rb', line 58

def has_file?(filename)
  files.any?{|file| file.to_name == filename || file.from_name == filename}
end

#num_filesObject



62
63
64
# File 'lib/manifestly/diff.rb', line 62

def num_files
  files.length
end