Class: Svn::Log::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/svnlog/index.rb

Overview

An index of svn log entries

Instance Method Summary collapse

Constructor Details

#initialize(path = nil, repository_url = nil) ⇒ Index

Returns a new instance of Index.



14
15
16
17
18
19
20
21
# File 'lib/svnlog/index.rb', line 14

def initialize(path = nil, repository_url = nil)
  @path = path
  @index = Ferret::Index::Index.new(:path => @path, :key => :revision)
  # load the properties
  properties_path = @path && File.join(@path, "properties.yml")
  @props = Properties.new(properties_path)
  @props[:repository_url] ||= repository_url
end

Instance Method Details

#closeObject

Close the index when you’re done with it



66
67
68
# File 'lib/svnlog/index.rb', line 66

def close
  @index.close
end

#last_revisionObject

Returns the revision number of the last entry indexed



34
35
36
# File 'lib/svnlog/index.rb', line 34

def last_revision
  @props[:last_revision]
end

#pathObject

Returns the path to the index



24
25
26
# File 'lib/svnlog/index.rb', line 24

def path
  @path
end

#repository_urlObject

Returns the url of the repository that is indexed



29
30
31
# File 'lib/svnlog/index.rb', line 29

def repository_url
  @props[:repository_url]
end

#search(query) ⇒ Object

Returns all entries that match the query



56
57
58
59
60
61
62
63
# File 'lib/svnlog/index.rb', line 56

def search(query)
  entries = []
  options = {:num_docs => @index.size, :sort => SortField::FIELD_DOC }
  for doc_id, score in @index.search(query, options)
    entries << @index[doc_id]
  end
  entries
end

#sizeObject

Returns the number of entries in the index



39
40
41
# File 'lib/svnlog/index.rb', line 39

def size
  @index.size
end

#updateObject

Updates the index with the latest entries



44
45
46
47
48
49
50
51
52
53
# File 'lib/svnlog/index.rb', line 44

def update
  revision = "#{last_revision.to_i}:HEAD"
  entries = Log.new(repository_url).find(revision)
  return if entries.size == 0
  for entry in entries
    add_entry(entry)
  end
  @index.flush
  @props[:last_revision] = entries.last[:revision]
end