Class: Lazylead::Svn::Commit

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

Overview

SVN commit built from command-line stdout (OS#run).

Instance Method Summary collapse

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

#authorObject



45
46
47
# File 'lib/lazylead/task/svn/svn.rb', line 45

def author
  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

#headerObject



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

Returns:

  • (Boolean)


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

#linesObject



57
58
59
# File 'lib/lazylead/task/svn/svn.rb', line 57

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

#msgObject



53
54
55
# File 'lib/lazylead/task/svn/svn.rb', line 53

def msg
  lines[1]
end

#revObject



41
42
43
# File 'lib/lazylead/task/svn/svn.rb', line 41

def rev
  header.first[1..]
end

#timeObject



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_sObject



37
38
39
# File 'lib/lazylead/task/svn/svn.rb', line 37

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