Class: PVN::Seek::Seeker
- Inherits:
-
Object
show all
- Includes:
- Logue::Loggable
- Defined in:
- lib/pvn/seek/seeker.rb
Instance Method Summary
collapse
-
#cat(revision) ⇒ Object
-
#diff_match(ifmatch, ifnomatch, prevmatch, currmatch) ⇒ Object
-
#full_diff?(ifmatch, ifnomatch) ⇒ Boolean
-
#initialize(path, pattern, revision, entries) ⇒ Seeker
constructor
A new instance of Seeker.
-
#match(idx) ⇒ Object
-
#matches?(previous_entry, current_entry) ⇒ Boolean
-
#process_match(ifmatch, ifnomatch, prevmatch, currmatch) ⇒ Object
-
#seek ⇒ Object
Constructor Details
#initialize(path, pattern, revision, entries) ⇒ Seeker
Returns a new instance of Seeker.
12
13
14
15
16
17
|
# File 'lib/pvn/seek/seeker.rb', line 12
def initialize path, pattern, revision, entries
@path = path
@pattern = pattern
@revision = revision
@entries = entries
end
|
Instance Method Details
#cat(revision) ⇒ Object
19
20
21
22
|
# File 'lib/pvn/seek/seeker.rb', line 19
def cat revision
ex = SVNx::CatExec.new path: @path, revision: revision, use_cache: true
ex.output
end
|
#diff_match(ifmatch, ifnomatch, prevmatch, currmatch) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/pvn/seek/seeker.rb', line 68
def diff_match ifmatch, ifnomatch, prevmatch, currmatch
difflines = ifmatch.diff ifnomatch
return if difflines.empty?
info "difflines: #{difflines}".color("cc33ff")
Match.new difflines.collect { |x| x[0] }, ifmatch.contents, prevmatch.previous_entry, currmatch.current_entry
end
|
#full_diff?(ifmatch, ifnomatch) ⇒ Boolean
58
59
60
|
# File 'lib/pvn/seek/seeker.rb', line 58
def full_diff? ifmatch, ifnomatch
return ifmatch if !ifnomatch
end
|
#match(idx) ⇒ Object
34
35
36
37
38
|
# File 'lib/pvn/seek/seeker.rb', line 34
def match idx
entry = @entries[idx]
preventry = idx > 0 ? @entries[idx - 1] : nil
matches? preventry, entry
end
|
#matches?(previous_entry, current_entry) ⇒ Boolean
24
25
26
27
28
29
30
31
32
|
# File 'lib/pvn/seek/seeker.rb', line 24
def matches? previous_entry, current_entry
contents = cat current_entry.revision
contents.collect! { |x| x.chomp! }
matchlnums = (0 ... contents.length).select do |lnum|
contents[lnum].index @pattern
end
return if matchlnums.empty?
Match.new matchlnums, contents, previous_entry, current_entry
end
|
#process_match(ifmatch, ifnomatch, prevmatch, currmatch) ⇒ Object
62
63
64
65
66
|
# File 'lib/pvn/seek/seeker.rb', line 62
def process_match ifmatch, ifnomatch, prevmatch, currmatch
return unless ifmatch
return ifmatch if full_diff? ifmatch, ifnomatch
diff_match ifmatch, ifnomatch, prevmatch, currmatch
end
|
#seek ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/pvn/seek/seeker.rb', line 40
def seek
latest_match = match 0
(1 ... @entries.size).each do |idx|
entry = @entries[idx]
current_match = match idx
if matchref = process_match(latest_match, current_match)
return Match.new matchref.lnums, matchref.contents, @entries[idx - 1], entry
end
if current_match
latest_match = current_match
end
end
nil
end
|