Class: Lazylead::Svn::Commit
- Inherits:
-
Object
- Object
- Lazylead::Svn::Commit
- Defined in:
- lib/lazylead/task/svn/svn.rb
Overview
SVN commit built from command-line stdout (OS#run).
Instance Method Summary collapse
-
#affected(text) ⇒ Object
Detect affected files with particular text.
- #author ⇒ Object
-
#diff(text) ⇒ Object
Detect SVN diff lines with particular text.
- #header ⇒ Object
-
#includes?(text) ⇒ Boolean
The modified lines contains expected text.
-
#initialize(raw) ⇒ Commit
constructor
A new instance of Commit.
- #lines ⇒ Object
- #msg ⇒ Object
- #rev ⇒ Object
- #time ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(raw) ⇒ Commit
Returns a new instance of Commit.
33 34 35 |
# File 'lib/lazylead/task/svn/svn.rb', line 33 def initialize(raw) @raw = raw end |
Instance Method Details
#affected(text) ⇒ Object
Detect affected files with particular text
83 84 85 86 87 88 89 90 |
# File 'lib/lazylead/task/svn/svn.rb', line 83 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 |
#author ⇒ Object
45 46 47 |
# File 'lib/lazylead/task/svn/svn.rb', line 45 def header[1] end |
#diff(text) ⇒ Object
Detect SVN diff lines with particular text
72 73 74 75 76 77 78 79 80 |
# File 'lib/lazylead/task/svn/svn.rb', line 72 def diff(text) @diff ||= begin files = affected(text).uniq @raw.split("Index: ") .select { |i| files.any? { |f| i.start_with? f } } .map { |i| i.split "\n" } .flatten end end |
#header ⇒ Object
61 62 63 |
# File 'lib/lazylead/task/svn/svn.rb', line 61 def header @header ||= lines.first.split(" | ").reject(&:blank?) end |
#includes?(text) ⇒ Boolean
The modified lines contains expected text
66 67 68 69 |
# File 'lib/lazylead/task/svn/svn.rb', line 66 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 |
#lines ⇒ Object
57 58 59 |
# File 'lib/lazylead/task/svn/svn.rb', line 57 def lines @lines ||= @raw.split("\n").reject(&:blank?) end |
#msg ⇒ Object
53 54 55 |
# File 'lib/lazylead/task/svn/svn.rb', line 53 def msg lines[1] end |
#rev ⇒ Object
41 42 43 |
# File 'lib/lazylead/task/svn/svn.rb', line 41 def rev header.first[1..] end |
#time ⇒ Object
49 50 51 |
# File 'lib/lazylead/task/svn/svn.rb', line 49 def time DateTime.parse(header[2]).strftime("%d-%m-%Y %H:%M:%S") end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/lazylead/task/svn/svn.rb', line 37 def to_s "#{rev} #{msg}" end |