Class: Lazylead::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/lazylead/task/svn/grep.rb

Overview

Single SVN commit details

Instance Method Summary collapse

Constructor Details

#initialize(commit) ⇒ Entry

Returns a new instance of Entry.



79
80
81
# File 'lib/lazylead/task/svn/grep.rb', line 79

def initialize(commit)
  @commit = commit
end

Instance Method Details

#affected(text) ⇒ Object

Detect affected files with particular text



130
131
132
133
134
135
136
137
# File 'lib/lazylead/task/svn/grep.rb', line 130

def affected(text)
  occurrences = lines.each_index.select do |i|
    lines[i].start_with?("+") && text.any? { |t| lines[i].include? t }
  end
  occurrences.map do |occ|
    lines[2..occ].reverse.find { |l| l.start_with? "Index: " }[7..]
  end
end

#authorObject



91
92
93
# File 'lib/lazylead/task/svn/grep.rb', line 91

def author
  header[1]
end

#diff(text) ⇒ Object

Detect SVN diff lines with particular text



119
120
121
122
123
124
125
126
127
# File 'lib/lazylead/task/svn/grep.rb', line 119

def diff(text)
  @diff ||= begin
    files = affected(text).uniq
    @commit.split("Index: ")
           .select { |i| files.any? { |f| i.start_with? f } }
           .map { |i| i.split "\n" }
           .flatten
  end
end

#headerObject



114
115
116
# File 'lib/lazylead/task/svn/grep.rb', line 114

def header
  @header ||= lines.first.split(" | ").reject(&:blank?)
end

#includes?(text) ⇒ Boolean

The modified lines contains expected text

Returns:

  • (Boolean)


104
105
106
107
108
# File 'lib/lazylead/task/svn/grep.rb', line 104

def includes?(text)
  text = [text] unless text.respond_to? :each
  lines[4..].select { |l| l.start_with? "+" }
            .any? { |l| text.any? { |t| l.include? t } }
end

#linesObject



110
111
112
# File 'lib/lazylead/task/svn/grep.rb', line 110

def lines
  @lines ||= @commit.split("\n").reject(&:blank?)
end

#msgObject



99
100
101
# File 'lib/lazylead/task/svn/grep.rb', line 99

def msg
  lines[1]
end

#revObject



87
88
89
# File 'lib/lazylead/task/svn/grep.rb', line 87

def rev
  header.first[1..]
end

#timeObject



95
96
97
# File 'lib/lazylead/task/svn/grep.rb', line 95

def time
  header[2]
end

#to_sObject



83
84
85
# File 'lib/lazylead/task/svn/grep.rb', line 83

def to_s
  "#{rev} #{msg}"
end