Class: StepUp::RangedNotes

Inherits:
Object
  • Object
show all
Defined in:
lib/step-up/ranged_notes.rb

Constant Summary collapse

COMMIT_NOTE =
0
NOTE =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver, first_commit = nil, last_commit = "HEAD", options = {}) ⇒ RangedNotes

Returns a new instance of RangedNotes.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
# File 'lib/step-up/ranged_notes.rb', line 8

def initialize(driver, first_commit = nil, last_commit = "HEAD", options={})
  @include_initial_tag_notes = !options[:exclude_initial_tag_notes]
  @notes_sections = notes_sections(options[:notes_sections])
  @driver = driver
  @last_commit = driver.commit_history(last_commit, 1).first
  first_commit = driver.commit_history(first_commit, 1).first unless first_commit.nil?
  raise ArgumentError, "The object #{ first_commit.inspect } was not found" unless first_commit.nil? || all_commits.include?(first_commit)
  @first_commit = first_commit
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



6
7
8
# File 'lib/step-up/ranged_notes.rb', line 6

def driver
  @driver
end

#first_commitObject (readonly)

Returns the value of attribute first_commit.



6
7
8
# File 'lib/step-up/ranged_notes.rb', line 6

def first_commit
  @first_commit
end

#last_commitObject (readonly)

Returns the value of attribute last_commit.



6
7
8
# File 'lib/step-up/ranged_notes.rb', line 6

def last_commit
  @last_commit
end

Instance Method Details

#all_commitsObject



30
31
32
# File 'lib/step-up/ranged_notes.rb', line 30

def all_commits
  @all_commits ||= driver.commit_history(last_commit)
end

#all_notesObject



22
23
24
# File 'lib/step-up/ranged_notes.rb', line 22

def all_notes
  (visible_detached_notes + scoped_commit_notes + scoped_attached_notes).sort.reverse.extend NotesArray
end

#notesObject



18
19
20
# File 'lib/step-up/ranged_notes.rb', line 18

def notes
  (visible_detached_notes + scoped_commit_notes).sort.reverse.extend NotesArray
end

#notes_of(commit) ⇒ Object



26
27
28
# File 'lib/step-up/ranged_notes.rb', line 26

def notes_of(commit)
  all_visible_notes.select{ |note| note[3] == commit }.extend NotesArray
end

#scoped_commitsObject



34
35
36
# File 'lib/step-up/ranged_notes.rb', line 34

def scoped_commits
  @scoped_commits ||= driver.commits_between(first_commit, last_commit, :with_messages => true).compact
end

#scoped_tagsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/step-up/ranged_notes.rb', line 38

def scoped_tags
  unless defined? @scoped_tags
    tags = []
    commits = scoped_commits.collect(&:first)
    all_version_tags = driver.all_version_tags
    unless all_version_tags.empty?
      all_version_tags.each do |version_tag|
        object = driver.commit_history(version_tag, 1).first
        tags << version_tag if commits.include?(object)
      end
      if !tags.empty? && include_initial_tag_notes?
        initial_tag_version_position = all_version_tags.index(tags.last).next
        initial_tag_version = all_version_tags[initial_tag_version_position]
        tags << initial_tag_version if initial_tag_version
      end
    end
    @scoped_tags = tags
  end
  @scoped_tags
end