Class: GitAwesomeDiff::Diff

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, exclude_paths = '') ⇒ Diff

Returns a new instance of Diff.



5
6
7
8
9
10
11
12
13
14
# File 'lib/git_awesome_diff/diff.rb', line 5

def initialize(path, exclude_paths = '')
  @path, @exclude_paths = path, exclude_paths

  load_repo

  validate!
  return false unless valid?

  save_head
end

Instance Attribute Details

#added_objects ⇒ Object (readonly)

Returns the value of attribute added_objects.



3
4
5
# File 'lib/git_awesome_diff/diff.rb', line 3

def added_objects
  @added_objects
end

#errors ⇒ Object (readonly)

Returns the value of attribute errors.



3
4
5
# File 'lib/git_awesome_diff/diff.rb', line 3

def errors
  @errors
end

#exclude_paths ⇒ Object (readonly)

Returns the value of attribute exclude_paths.



3
4
5
# File 'lib/git_awesome_diff/diff.rb', line 3

def exclude_paths
  @exclude_paths
end

#head ⇒ Object (readonly)

Returns the value of attribute head.



3
4
5
# File 'lib/git_awesome_diff/diff.rb', line 3

def head
  @head
end

#path ⇒ Object (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/git_awesome_diff/diff.rb', line 3

def path
  @path
end

#removed_objects ⇒ Object (readonly)

Returns the value of attribute removed_objects.



3
4
5
# File 'lib/git_awesome_diff/diff.rb', line 3

def removed_objects
  @removed_objects
end

#repo ⇒ Object (readonly)

Returns the value of attribute repo.



3
4
5
# File 'lib/git_awesome_diff/diff.rb', line 3

def repo
  @repo
end

Instance Method Details

#diff!(*refs) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/git_awesome_diff/diff.rb', line 20

def diff!(*refs)
  ref1 = parse_rev(refs.shift || 'HEAD~1')
  ref2 = parse_rev(refs.shift || 'master')
  registry = []

  @added_objects, @removed_objects = [], []

  begin
    checkout(ref1)
    registry << generate_yardoc

    checkout(ref2)
    registry << generate_yardoc

    @added_objects = (registry[1] - registry[0]).sort
    @removed_objects = (registry[0] - registry[1]).sort
  ensure
    checkout(head)
  end

  self
end

#valid? ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/git_awesome_diff/diff.rb', line 16

def valid?
  errors.blank?
end