Class: IssueBeaver::Models::Merger

Inherits:
Object
  • Object
show all
Defined in:
lib/issue_beaver/models/merger.rb

Instance Method Summary collapse

Constructor Details

#initialize(issues, todos, repo) ⇒ Merger

Returns a new instance of Merger.



7
8
9
10
11
# File 'lib/issue_beaver/models/merger.rb', line 7

def initialize(issues, todos, repo)
  @issues = issues
  @matcher = Matcher.new(@issues, todos)
  @repo = repo
end

Instance Method Details

#addedObject



14
15
16
# File 'lib/issue_beaver/models/merger.rb', line 14

def added
  @added ||= merged_issues.select(&:new?)
end

#changedObject



24
25
26
# File 'lib/issue_beaver/models/merger.rb', line 24

def changed
  @changed ||= added.merge_left(modified).merge_left(closed, :number)
end

#closedObject



29
30
31
# File 'lib/issue_beaver/models/merger.rb', line 29

def closed
  @closed ||= unmatched_issues.select(&:must_close?)
end

#merged_issuesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/issue_beaver/models/merger.rb', line 34

def merged_issues
  @merged_issues ||=
  @matcher.matches.map do |todo, issue|
    if issue
      if todo.updated_at > issue.updated_at
        issue.update_attributes(todo.attributes)
      end
    else
      issue = todo
    end
    issue
  end
end

#modifiedObject



19
20
21
# File 'lib/issue_beaver/models/merger.rb', line 19

def modified
  @modified ||= merged_issues.select(&:must_update?)
end

#unmatched_issuesObject

TODO: Tidy up a bit



49
50
51
52
53
54
55
56
57
58
# File 'lib/issue_beaver/models/merger.rb', line 49

def unmatched_issues
  @unmatched_issues ||=
    Enumerator.new do |yielder|
      @issues.to_a.each do |issue|
        next if merged_issues.to_a.map{|issue| issue.attributes.number }.compact.include? issue.number
        issue.mark_for_closing if @repo.is_ahead?(issue.commit)
        yielder << issue
      end
    end.memoizing.lazy
end