Class: SVNDataCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/codespicuous/svn_data_collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, commit_history = CommitHistory.new) ⇒ SVNDataCollector

Returns a new instance of SVNDataCollector.



7
8
9
10
# File 'lib/codespicuous/svn_data_collector.rb', line 7

def initialize(config, commit_history = CommitHistory.new)
  @commit_history = commit_history
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/codespicuous/svn_data_collector.rb', line 5

def config
  @config
end

Instance Method Details

#collect_commit_history(repositories) ⇒ Object



43
44
45
46
47
48
# File 'lib/codespicuous/svn_data_collector.rb', line 43

def collect_commit_history(repositories)
  repositories.each { | repository|
    @commit_history.add_commits(collect_commits_for_repository(repository))
  }
  @commit_history
end

#collect_commits_for_repository(repository) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/codespicuous/svn_data_collector.rb', line 34

def collect_commits_for_repository(repository)
    puts "Getting svn log from repository: " + repository.name
    xmllog = retrieve_svn_log_from(repository)
    save_svn_log(repository, xmllog)
    commits_in_repository = retrieve_commits_from_log(xmllog)
    commits_in_repository.set_repository(repository)
    commits_in_repository
end

#retrieve_commits_from_log(xmllog) ⇒ Object



23
24
25
26
27
# File 'lib/codespicuous/svn_data_collector.rb', line 23

def retrieve_commits_from_log(xmllog)
  parser = SVNLogParser.new
  parser.parse(xmllog)
  parser.commits
end

#retrieve_svn_log_from(repository) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/codespicuous/svn_data_collector.rb', line 12

def retrieve_svn_log_from(repository)
  if config.offline
    File.read(config.path_to_cached_svn_log(repository.name))
  else
    svn = SVNClient.new
    svn.repository(repository.url)
    now = DateTime.now
    svn.log_xml(now.prev_year, now)
  end
end

#save_svn_log(repository, xmllog) ⇒ Object



29
30
31
32
# File 'lib/codespicuous/svn_data_collector.rb', line 29

def save_svn_log(repository, xmllog)
  Dir.mkdir(config.path_to_cached_svn_log_dir) unless Dir.exists?(config.path_to_cached_svn_log_dir)
  File.write(config.path_to_cached_svn_log(repository.name), xmllog)
end