Class: Bringit::Compare

Inherits:
Object
  • Object
show all
Defined in:
lib/bringit/compare.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, base, head, straight = false) ⇒ Compare

Returns a new instance of Compare.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bringit/compare.rb', line 5

def initialize(repository, base, head, straight = false)
  @repository = repository
  @straight = straight

  unless base && head
    @commits = []
    return
  end

  @base = Bringit::Commit.find(repository, base.try(:strip))
  @head = Bringit::Commit.find(repository, head.try(:strip))

  @commits = [] unless @base && @head
  @commits = [] if same
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



3
4
5
# File 'lib/bringit/compare.rb', line 3

def base
  @base
end

#headObject (readonly)

Returns the value of attribute head.



3
4
5
# File 'lib/bringit/compare.rb', line 3

def head
  @head
end

#straightObject (readonly)

Returns the value of attribute straight.



3
4
5
# File 'lib/bringit/compare.rb', line 3

def straight
  @straight
end

Instance Method Details

#commitsObject



25
26
27
28
29
# File 'lib/bringit/compare.rb', line 25

def commits
  return @commits if defined?(@commits)

  @commits = Bringit::Commit.between(@repository, @base.id, @head.id)
end

#diffs(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/bringit/compare.rb', line 31

def diffs(options = {})
  unless @head && @base
    return Bringit::DiffCollection.new([])
  end

  paths = options.delete(:paths) || []
  options[:straight] = @straight
  Bringit::Diff.between(@repository, @head.id, @base.id, options, *paths)
end

#sameObject



21
22
23
# File 'lib/bringit/compare.rb', line 21

def same
  @base && @head && @base.id == @head.id
end